Revision cb397ea3
Von Moritz Bunkus vor fast 5 Jahren hinzugefügt
t/helper/datetime.t | ||
---|---|---|
1 |
use Test::More tests => 50;
|
|
1 |
use Test::More tests => 60;
|
|
2 | 2 |
|
3 | 3 |
use lib 't'; |
4 | 4 |
|
... | ... | |
7 | 7 |
use DateTime; |
8 | 8 |
use_ok 'SL::Helper::DateTime'; |
9 | 9 |
|
10 |
my $local_tz = DateTime::TimeZone->new(name => 'local'); |
|
11 |
my $mon_012345 = DateTime->new(year => 2014, month => 6, day => 23, hour => 1, minute => 23, second => 45, time_zone => $local_tz); |
|
12 |
|
|
10 | 13 |
sub mon { DateTime->new(year => 2014, month => 6, day => 23) } |
11 | 14 |
sub tue { DateTime->new(year => 2014, month => 6, day => 24) } |
12 | 15 |
sub wed { DateTime->new(year => 2014, month => 6, day => 25) } |
... | ... | |
87 | 90 |
is sat->add_businessdays(days => 1), sat->add(days => 2), "1 day after sut is mon"; |
88 | 91 |
is sun->add_businessdays(days => -1), sun->add(days => -2), "1 day before sun is fri"; |
89 | 92 |
is sat->add_businessdays(days => -1), sat->add(days => -1), "1 day before sut is fri"; |
93 |
|
|
94 |
# parsing YYYY-MM-DD formatted strings |
|
95 |
is(DateTime->from_ymd(), undef, "no argument results in undef"); |
|
96 |
is(DateTime->from_ymd(''), undef, "empty argument results in undef"); |
|
97 |
is(DateTime->from_ymd('chunky bacon'), undef, "invalid argument results in undef"); |
|
98 |
is(DateTime->from_ymd('2014-06-23'), $mon_012345->clone->truncate(to => 'day'), "2014-06-23 is parsed correctly"); |
|
99 |
is(DateTime->from_ymd('2014-06-23')->strftime('%H%M%S'), '000000', "2014-06-23 is parsed correctly"); |
|
100 |
|
|
101 |
# parsing YYYY-MM-DDTHH:MM:SS formatted strings |
|
102 |
is(DateTime->from_ymdhms(), undef, "no argument results in undef"); |
|
103 |
is(DateTime->from_ymdhms(''), undef, "empty argument results in undef"); |
|
104 |
is(DateTime->from_ymdhms('chunky bacon'), undef, "invalid argument results in undef"); |
|
105 |
is(DateTime->from_ymdhms('2014-06-23T01:23:45'), $mon_012345, "2014-06-23T01:23:45 is parsed correctly"); |
|
106 |
is(DateTime->from_ymdhms('2014-06-23 01:23:45'), $mon_012345, "2014-06-23 01:23:45 is parsed correctly"); |
Auch abrufbar als: Unified diff
DateTime: Funktionen zum Parsen von YYYY:MM:DD und YYYY:MM:DDTHH:MM:SS