Subject: | Clone fails on floating time zone object? |
I had some tests fail (clone.t) while installing DateTime::Calendar::Hebrew
The tests seemed to fail in DateTime.pm's from_object() method, if
$object->time_zone was 'floating' rather than a TimeZone object. The
patch below (and attached) seemed to quash the error -- I don't actually
know if this is a problem with the DateTime.pm code or the
DateTime::Calendar::Hebrew code but here it is.
All I did was copy the earlier snippet (setting $self->{tz}) so that if
the time_zone is a string it is objectified.
=====================================================================
Here is the relevant code from DateTime::Calendar::Hebrew:
use DateTime::Calendar::Hebrew;
use DateTime::Event::Sunrise;
print "1..1\n";
my $sunset = DateTime::Event::Sunrise->sunset (
# Latitude/Longitude for NYC
longitude =>'-73.59',
latitude =>'40.38',
);
# the date the Ancient Israelites left Egypt
my $DT = new DateTime::Calendar::Hebrew(
year => 2449,
month => 1,
day => 15,
hour => 23,
minute => 59,
second => 0,
nanosecond => 987654321,
time_zone => 'America/New_York',
sunset => $sunset,
);
my $clone = $DT->clone;
print Dumper $clone;
if($DT->utc_rd_as_seconds == $clone->utc_rd_as_seconds) { print "ok\n"; }
else { print "not ok\n"; }
exit;
=====================================================================
--- DateTime.pm 2007-09-10 10:41:27.000000000 -0500
+++ DateTime-fix.pm 2007-12-01 12:13:37.037559308 -0600
@@ -509,13 +509,21 @@
# on the given value. If the object _is_ on a leap second, we'll
# add that to the generated seconds value later.
my $leap_seconds = 0;
- if ( $object->can('time_zone') && ! $object->time_zone->is_floating
+
+ if ( $object->can('time_zone') ) {
+ my $tz =
+ ( ref $object->time_zone ?
+ $object->time_zone :
+ DateTime::TimeZone->new( name => $object->time_zone )
+ );
+
+ if ( ! $tz->is_floating
&& $rd_secs > 86399 && $rd_secs <=
$class->_day_length($rd_days) )
{
$leap_seconds = $rd_secs - 86399;
$rd_secs -= $leap_seconds;
}
-
+ }
my %args;
@args{ qw( year month day ) } = $class->_rd2ymd($rd_days);
@args{ qw( hour minute second ) } =
Subject: | clone.t |
use DateTime::Calendar::Hebrew;
use DateTime::Event::Sunrise;
print "1..1\n";
my $sunset = DateTime::Event::Sunrise->sunset (
# Latitude/Longitude for NYC
longitude =>'-73.59',
latitude =>'40.38',
);
# the date the Ancient Israelites left Egypt
my $DT = new DateTime::Calendar::Hebrew(
year => 2449,
month => 1,
day => 15,
hour => 23,
minute => 59,
second => 0,
nanosecond => 987654321,
time_zone => 'America/New_York',
sunset => $sunset,
);
my $clone = $DT->clone;
print Dumper $clone;
if($DT->utc_rd_as_seconds == $clone->utc_rd_as_seconds) { print "ok\n"; }
else { print "not ok\n"; }
exit;
Subject: | DateTime-patch.pm |
--- DateTime.pm 2007-09-10 10:41:27.000000000 -0500
+++ DateTime-fix.pm 2007-12-01 12:13:37.037559308 -0600
@@ -509,13 +509,21 @@
# on the given value. If the object _is_ on a leap second, we'll
# add that to the generated seconds value later.
my $leap_seconds = 0;
- if ( $object->can('time_zone') && ! $object->time_zone->is_floating
+
+ if ( $object->can('time_zone') ) {
+ my $tz =
+ ( ref $object->time_zone ?
+ $object->time_zone :
+ DateTime::TimeZone->new( name => $object->time_zone )
+ );
+
+ if ( ! $tz->is_floating
&& $rd_secs > 86399 && $rd_secs <= $class->_day_length($rd_days) )
{
$leap_seconds = $rd_secs - 86399;
$rd_secs -= $leap_seconds;
}
-
+ }
my %args;
@args{ qw( year month day ) } = $class->_rd2ymd($rd_days);
@args{ qw( hour minute second ) } =