When converting a DateTime object from floating time to another time
zone, its utc time is not adjusted. Most of the methods use the local
time, but there are problems if you compare datetimes, for example.
Take this example, where the two created days should be equal:
my $dt1 = DateTime->new( year => 2003, month => 3, day => 23, hour => 12,
time_zone => 'America/Chicago' );
print "local 1: ", $dt1->local_rd_as_seconds, "\n";
print "utc 1: ", $dt1->utc_rd_as_seconds, "\n";
my $dt2 = DateTime->new( year => 2003, month => 3, day => 23, hour => 12 )
->set_time_zone('America/Chicago');
print "local 2: ", $dt2->local_rd_as_seconds, "\n";
print "utc 2: ", $dt2->utc_rd_as_seconds, "\n";
print '$dt1 <=> $dt2: ', $dt1 <=> $dt2, "\n";
Patch for DateTime.pm and testfile below.
Eugene
diff -ur DateTime-0.08/lib/DateTime.pm DateTime-new/lib/DateTime.pm
--- DateTime-0.08/lib/DateTime.pm Fri Mar 21 07:02:27 2003
+++ DateTime-new/lib/DateTime.pm Sun Mar 23 22:08:28 2003
@@ -793,7 +793,7 @@
$self->{tz} = ref $tz ? $tz : DateTime::TimeZone->new( name => $tz );
- if ( $self->{tz}->is_floating && ! $was_floating )
+ if ( $self->{tz}->is_floating xor $was_floating )
{
$self->_calc_utc_rd;
}
diff -ur DateTime-0.08/t/05tz.t DateTime-new/t/05tz.t
--- DateTime-0.08/t/05tz.t Mon Mar 17 06:36:14 2003
+++ DateTime-new/t/05tz.t Sun Mar 23 22:23:02 2003
@@ -1,6 +1,6 @@
use strict;
-use Test::More tests => 68;
+use Test::More tests => 70;
use DateTime;
@@ -122,6 +122,8 @@
$dt->set_time_zone( 'America/Chicago' );
is( $dt->hour, 3, 'hour should be 3 after switching from floating TZ' );
+ is( $dt->local_rd_as_seconds - $dt->utc_rd_as_seconds, -18000,
+ 'tz offset should be -18000' );
}
{
@@ -131,6 +133,8 @@
$dt->set_time_zone( 'floating' );
is( $dt->hour, 3, 'hour should be 3 after switching to floating TZ' );
+ is( $dt->local_rd_as_seconds - $dt->utc_rd_as_seconds, 0,
+ 'tz offset should be 0' );
}
{