1#!/usr/bin/perl -w 2 3# test bug 3766 4# http://rt.cpan.org/NoAuth/Bug.html?id=3766 5# returns undef when you pass it a DateTime object 6# whose timezone has been explicitly set. 7 8# test bug 3771 9# http://rt.cpan.org/NoAuth/Bug.html?id=3771 10# format_datetime method a DateTime object whose timestamp is set 11# explicitly as "00:00:00", the method will not print a timestamp or an offset. 12 13use strict; 14use Test::More tests => 4; 15 16use DateTime; 17use DateTime::Format::W3CDTF; 18 19my @dates = ( 20 { date => { year => 1977, month => 11, day => 11, hour => 1, minute => 12, time_zone => 'America/Los_Angeles' }, 21 w3cdtf => '1977-11-11T01:12:00-08:00', 22 msg => 'formatter works with explicit timezone', 23 }, 24 { date => { year => 1977, month => 4, day => 7, time_zone => 'America/Los_Angeles' }, 25 w3cdtf => '1977-04-07T00:00:00-08:00', 26 msg => 'formatter works without timestamp', 27 }, 28 { date => { year => 2003, month => 4, day => 7, hour => 2, time_zone => 'America/Los_Angeles' }, 29 w3cdtf => '2003-04-07T02:00:00-07:00', 30 msg => 'formatter properly recognizing daylights saving' 31 }, 32 { date => { year => 2003, month => 12, day => 25, hour => 0, minute => 00, second => 00, time_zone => 'America/Montreal' }, 33 w3cdtf => '2003-12-25T00:00:00-05:00', 34 msg => 'formatter properly formats midnight' 35 } 36); 37my $f = DateTime::Format::W3CDTF->new(); 38 39foreach my $d ( @dates ) { 40 my $dt = DateTime->new( %{ $d->{date} } ); 41 is ( $f->format_datetime($dt), $d->{w3cdtf}, $d->{msg}); 42}