[Rt-devel] 3.6.0pre1 PATCH: fix searching of days
David Schweikert
dws at ee.ethz.ch
Fri Apr 14 05:43:54 EDT 2006
Hi,
I noticed that when searching for tickets that have a due date on a given
date, the searched date is wrong by one day.
The problem lies in the timezone handling and how the range for the day
is calculated.
In Tickets_Overlay.pm there is the following code:
# if we're specifying =, that means we want everything on a
# particular single day. in the database, we need to check for >
# and < the edges of that day.
my $daystart = strftime( "%Y-%m-%d %H:%M",
gmtime( $time - ( $time % 86400 ) ) );
my $dayend = strftime( "%Y-%m-%d %H:%M",
gmtime( $time + ( 86399 - $time % 86400 ) ) );
Note that when you enter a date, it is parsed in the local time zone (which is
a good thing to do) and, unless you specify it, the time is set to 00:00:00.
So, if you search for 2006-04-14 in my timezone (+0200), it will be parsed as
2006-04-14 00:00:00 +0200. The Unix time is however stored in UTC, so
internally it is 2006-04-13 22:00:00 +0000. Using the above formulas, it gives:
daystart = 2006-04-13 00:00:00 +0000
dayend = 2006-04-13 23:59:59 +0000
... which is not what I expect when searching.
The attached patch fixes this problem.
Cheers
David
PS: Even better would be not to use the Unix time directly but instead
use a module like Date::Calc.
--
David Schweikert | phone: +41 44 632 7019
System manager ISG.EE | walk: ETH Zentrum, ETL F24.1
ETH Zurich, Switzerland | web: http://people.ee.ethz.ch/dws
-------------- next part --------------
--- RT/Tickets_Overlay.pm~ 2006-02-17 03:29:14.000000000 +0100
+++ RT/Tickets_Overlay.pm 2006-04-14 11:26:06.389202000 +0200
@@ -480,12 +480,12 @@
# if we're specifying =, that means we want everything on a
# particular single day. in the database, we need to check for >
- # and < the edges of that day.
+ # and < the edges of that day in the local timezone.
- my $daystart = strftime( "%Y-%m-%d %H:%M",
- gmtime( $time - ( $time % 86400 ) ) );
- my $dayend = strftime( "%Y-%m-%d %H:%M",
- gmtime( $time + ( 86399 - $time % 86400 ) ) );
+ my @time_local = localtime($time);
+ my $daystart_t = $time-$time_local[2]*3600-$time_local[1]*60-$time_local[0];
+ my $daystart = strftime( "%Y-%m-%d %H:%M", gmtime( $daystart_t ));
+ my $dayend = strftime( "%Y-%m-%d %H:%M", gmtime( $daystart_t + 86399 ));
$sb->_OpenParen;
More information about the Rt-devel
mailing list