[Rt-commit] rt branch, 4.4/user-timezone-in-date-eq-sql, created. rt-4.4.3-62-g82d92b907
? sunnavy
sunnavy at bestpractical.com
Fri Oct 19 11:34:27 EDT 2018
The branch, 4.4/user-timezone-in-date-eq-sql has been created
at 82d92b9072eab550a38ad9a7f0dfcfb2c405c93b (commit)
- Log -----------------------------------------------------------------
commit a6fc87ebb3729d1fe9128651731634ba97d6c14c
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Oct 19 04:29:30 2018 +0800
Use user timezone for date "=" queries in ticket search
Take query "Updated = '2018-10-17'" for example, it means tickets
updated on 2018-10-17, which should always be equal to query:
Updated >= "2018-10-17 00:00:00" and Updated < "2018-10-18 00:00:00"
Previously, if current user's timezone is not the same as the default
one(in RT config), e.g. if user and default are "UTC" and "-04:00",
respectively, the above "Updated = '2018-10-17'" query is actually equal
to:
Updated >= "2018-10-16 20:00:00" and Updated < "2018-10-17 20:00:00"
which is not right.
This commit fixes this inconsistence.
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index a2b27bf4d..35700d387 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -640,7 +640,7 @@ sub _DateLimit {
# particular single day. in the database, we need to check for >
# and < the edges of that day.
- $date->SetToMidnight( Timezone => 'server' );
+ $date->SetToMidnight( Timezone => 'user' );
my $daystart = $date->ISO;
$date->AddDay;
my $dayend = $date->ISO;
@@ -787,7 +787,7 @@ sub _TransDateLimit {
# particular single day. in the database, we need to check for >
# and < the edges of that day.
- $date->SetToMidnight( Timezone => 'server' );
+ $date->SetToMidnight( Timezone => 'user' );
my $daystart = $date->ISO;
$date->AddDay;
my $dayend = $date->ISO;
commit 82d92b9072eab550a38ad9a7f0dfcfb2c405c93b
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Oct 19 23:17:57 2018 +0800
Test the timezone fix for date "=" queries
diff --git a/t/ticket/search.t b/t/ticket/search.t
index 2845dd8bc..29022635b 100644
--- a/t/ticket/search.t
+++ b/t/ticket/search.t
@@ -5,7 +5,7 @@
use strict;
use warnings;
-use RT::Test nodata => 1, tests => undef;
+use RT::Test tests => undef;
# setup the queue
@@ -327,5 +327,23 @@ $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL('Lifecycle="approvals"');
is($tix->Count,0,"We found 0 tickets in a queue with the approvals lifecycle");
+# tests for Created date
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Created = "2018-10-05"');
+is($tix->Count, 0, "We found 0 tickets created in 2018-10-05");
+
+ok($t1->__Set(Field => 'Created', Value => '2018-10-05 06:10:00'), 'Updated t1 Created to 2018-10-05 06:10:00');
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Created = "2018-10-05"');
+is($tix->Count, 1, "We found 1 ticket created in 2018-10-05 with system user");
+
+my $user = RT::CurrentUser->new(RT->SystemUser);
+ok($user->Load('root'), 'Loaded root');
+ok($user->UserObj->SetTimezone('Asia/Shanghai'), 'Updated root timezone to +08:00');
+
+$tix = RT::Tickets->new($user);
+$tix->FromSQL('Created = "2018-10-05"');
+is($tix->Count, 1, "We found 1 ticket created in 2018-10-05 with user in +08:00 timezone");
done_testing;
diff --git a/t/ticket/search_by_txn.t b/t/ticket/search_by_txn.t
index 6f970aadc..d89035d40 100644
--- a/t/ticket/search_by_txn.t
+++ b/t/ticket/search_by_txn.t
@@ -5,7 +5,7 @@ use strict;
BEGIN{ $ENV{'TZ'} = 'GMT'};
-use RT::Test tests => 10;
+use RT::Test tests => undef;
my $SUBJECT = "Search test - ".$$;
@@ -24,11 +24,31 @@ my ($id, $txnid, $txnobj) = $ticket->Comment( Content => 'A comment that happen
isa_ok($txnobj, 'RT::Transaction');
ok($txnobj->CreatedObj->ISO);
-my ( $sid,$smsg) = $txnobj->__Set(Field => 'Created', Value => '2005-08-05 20:00:56');
-ok($sid,$smsg);
-is($txnobj->Created,'2005-08-05 20:00:56');
-is($txnobj->CreatedObj->ISO,'2005-08-05 20:00:56');
+my $user = RT::CurrentUser->new( RT->SystemUser );
+ok( $user->Load('root'), 'Loaded user root' );
+ok( $user->UserObj->SetTimezone('Asia/Shanghai'), 'Updated root timezone to +08:00' );
+
+ok($txnobj->__Set(Field => 'Created', Value => '2005-08-05 20:00:56'), 'Updated txn created to UTC 2005-08-05 20:00:56');
+is($txnobj->Created, '2005-08-05 20:00:56', 'Created date');
+is($txnobj->CreatedObj->ISO, '2005-08-05 20:00:56', 'Created ISO');
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL(qq{Updated = "2005-08-05" AND Subject = "$SUBJECT"});
+is($tix->Count, 1, "Found the ticket using 2005-08-05 for system user");
+
+$tix = RT::Tickets->new($user);
+$tix->FromSQL(qq{Updated = "2005-08-06" AND Subject = "$SUBJECT"});
+is($tix->Count, 1, "Found the ticket using 2005-08-06 for user in +08:00 timezone");
+
+ok($txnobj->__Set(Field => 'Created', Value => '2005-08-05 06:00:56'), 'Updated txn created to UTC 2005-08-05 06:00:56');
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL(qq{Updated = "2005-08-05" AND Subject = "$SUBJECT"});
+is($tix->Count, 1, "Found the ticket using 2005-08-05 for system user");
+
+$tix = RT::Tickets->new($user);
$tix->FromSQL(qq{Updated = "2005-08-05" AND Subject = "$SUBJECT"});
-is( $tix->Count, 1);
+is($tix->Count, 1, "Found the ticket using 2005-08-05 for user in +08:00 timezone");
+done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list