
ruz at bestpractical
Jul 22, 2008, 12:29 PM
Post #1 of 1
(60 views)
Permalink
|
|
r14395 - in rt/3.8/trunk: lib/RT sbin
|
|
Author: ruz Date: Tue Jul 22 15:29:06 2008 New Revision: 14395 Modified: rt/3.8/trunk/lib/RT/Date.pm rt/3.8/trunk/sbin/rt-test-dependencies.in rt/3.8/trunk/t/api/date.t Log: * fix handling of relative dates entered by user * add tests using Test::MockTime Modified: rt/3.8/trunk/lib/RT/Date.pm ============================================================================== --- rt/3.8/trunk/lib/RT/Date.pm (original) +++ rt/3.8/trunk/lib/RT/Date.pm Tue Jul 22 15:29:06 2008 @@ -191,10 +191,14 @@ elsif ( $args{'Format'} =~ /^unknown$/i ) { require Time::ParseDate; # the module supports only legacy timezones like PDT or EST... - # so we parse date as GMT and later apply offset + # so we parse date as GMT and later apply offset, this only + # should be applied to absolute times, so compensate shift in NOW + my $now = time; + $now += ($self->Localtime( $args{Timezone}, $now ))[9]; my $date = Time::ParseDate::parsedate( $args{'Value'}, GMT => 1, + NOW => $now, UK => RT->Config->Get('DateDayBeforeMonth'), PREFER_PAST => RT->Config->Get('AmbiguousDayInPast'), PREFER_FUTURE => RT->Config->Get('AmbiguousDayInFuture'), Modified: rt/3.8/trunk/sbin/rt-test-dependencies.in ============================================================================== --- rt/3.8/trunk/sbin/rt-test-dependencies.in (original) +++ rt/3.8/trunk/sbin/rt-test-dependencies.in Tue Jul 22 15:29:06 2008 @@ -294,6 +294,7 @@ Test::Warn Test::Builder 0.77 # needed to fix TODO test IPC::Run3 +Test::MockTime . $deps{'FASTCGI'} = [ text_to_hash( << '.') ]; Modified: rt/3.8/trunk/t/api/date.t ============================================================================== --- rt/3.8/trunk/t/api/date.t (original) +++ rt/3.8/trunk/t/api/date.t Tue Jul 22 15:29:06 2008 @@ -1,6 +1,8 @@ #!/usr/bin/perl -use Test::More tests => 165; +use Test::MockTime qw(set_fixed_time restore_time); + +use Test::More tests => 167; use warnings; use strict; use RT::Test; @@ -316,6 +318,17 @@ $date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00', Timezone => 'utc' ); is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss"); + # test relative dates + { + set_fixed_time("2005-11-28T15:10:00Z"); + $date->Set(Format => 'unknown', Value => 'now'); + is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss"); + + $date->Set(Format => 'unknown', Value => '1 day ago'); + is($date->ISO, '2005-11-27 15:10:00', "YYYY-DD-MM hh:mm:ss"); + restore_time(); + } + RT->Config->Set( Timezone => 'UTC' ); $date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00'); is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss"); _______________________________________________ Rt-commit mailing list Rt-commit[at]lists.bestpractical.com http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit
|