Subject: | datetime_format doesn't handle Greenwich/London timezone |
format_datetime() does not work for the Europe/London timezone where
offset is 0. Fix with test case is attached.
dt=DateTime->now;
for $tz qw( America/Buenos_Aires
Atlantic/Cape_Verde
Europe/London
Europe/Paris
Europe/Moscow ){
$dt->set_time_zone($tz);
print DateTime::Format::W3CDTF->format_datetime($dt)
}
prints:
2006-11-03T16:24:18-03:00
2006-11-03T18:24:18-01:00
0
2006-11-03T20:24:18+01:00
2006-11-03T22:24:18+03:00
Subject: | dtf-w3cdtf-format_datetime.patch |
diff -u -Naur DateTime-Format-W3CDTF-0.04.orig/lib/DateTime/Format/W3CDTF.pm DateTime-Format-W3CDTF-0.04.fixed/lib/DateTime/Format/W3CDTF.pm
--- DateTime-Format-W3CDTF-0.04.orig/lib/DateTime/Format/W3CDTF.pm 2003-11-23 18:09:56.000000000 -0800
+++ DateTime-Format-W3CDTF-0.04.fixed/lib/DateTime/Format/W3CDTF.pm 2006-11-03 11:21:15.000000000 -0800
@@ -98,7 +98,7 @@
return $base . 'Z' if $tz->is_utc;
- if (my $offset = $dt->offset()) {
+ if (defined(my $offset = $dt->offset())) {
return $base . offset_as_string($offset );
}
}
diff -u -Naur DateTime-Format-W3CDTF-0.04.orig/t/02bugs.t DateTime-Format-W3CDTF-0.04.fixed/t/02bugs.t
--- DateTime-Format-W3CDTF-0.04.orig/t/02bugs.t 2003-11-23 18:09:56.000000000 -0800
+++ DateTime-Format-W3CDTF-0.04.fixed/t/02bugs.t 2006-11-03 11:21:00.000000000 -0800
@@ -11,7 +11,7 @@
# explicitly as "00:00:00", the method will not print a timestamp or an offset.
use strict;
-use Test::More tests => 4;
+use Test::More tests => 5;
use DateTime;
use DateTime::Format::W3CDTF;
@@ -32,11 +32,15 @@
{ date => { year => 2003, month => 12, day => 25, hour => 0, minute => 00, second => 00, time_zone => 'America/Montreal' },
w3cdtf => '2003-12-25T00:00:00-05:00',
msg => 'formatter properly formats midnight'
- }
+ },
+ { date => { year => 2003, month => 12, day => 25, hour => 0, minute => 00, second => 00, time_zone => 'Europe/London' },
+ w3cdtf => '2003-12-25T00:00:00+00:00',
+ msg => 'formatter properly handles offset==0'
+ },
);
my $f = DateTime::Format::W3CDTF->new();
foreach my $d ( @dates ) {
my $dt = DateTime->new( %{ $d->{date} } );
is ( $f->format_datetime($dt), $d->{w3cdtf}, $d->{msg});
-}
\ No newline at end of file
+}