[Rt-devel] 3.6.0pre1 PATCH: fix searching of days

Jesse Vincent jesse at bestpractical.com
Fri Apr 28 11:10:35 EDT 2006


David Schweikert wrote:
> 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.
> 


Looking through the backlog, the reason I didn't end up applying this
patch is due to the use of localtime(). Instead, it should use RT::Date,
as in RT 3.7, RT::Date should automatically handle the timezone
conversion to do the right thing for you. (Ruz, can you confirm that?)

Jesse

> 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.
> 
> 
> ------------------------------------------------------------------------
> 
> --- 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;
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel
> 
> Best Practical is hiring! Come hack Perl for us: http://bestpractical.com/about/jobs.html


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 191 bytes
Desc: OpenPGP digital signature
Url : http://lists.bestpractical.com/pipermail/rt-devel/attachments/20060428/dd237253/signature.pgp


More information about the Rt-devel mailing list