X-Git-Url: http://wagnertech.de/git?p=kivitendo-erp.git;a=blobdiff_plain;f=t%2Fhelper%2Fdatetime.t;fp=t%2Fhelper%2Fdatetime.t;h=4966540c994a46fdc7f1e20478cf5a9fb4c6c392;hp=afaa49e84cb4dc012b34c8b38b9c8e5d834552dc;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44 diff --git a/t/helper/datetime.t b/t/helper/datetime.t index afaa49e84..4966540c9 100644 --- a/t/helper/datetime.t +++ b/t/helper/datetime.t @@ -1,4 +1,4 @@ -use Test::More tests => 50; +use Test::More tests => 60; use lib 't'; @@ -7,6 +7,9 @@ use Data::Dumper; use DateTime; use_ok 'SL::Helper::DateTime'; +my $local_tz = DateTime::TimeZone->new(name => 'local'); +my $mon_012345 = DateTime->new(year => 2014, month => 6, day => 23, hour => 1, minute => 23, second => 45, time_zone => $local_tz); + sub mon { DateTime->new(year => 2014, month => 6, day => 23) } sub tue { DateTime->new(year => 2014, month => 6, day => 24) } sub wed { DateTime->new(year => 2014, month => 6, day => 25) } @@ -45,7 +48,7 @@ is tue->add_businessdays(businessweek => 6, days => 9), tue->add(days => 10), "t is tue->add_businessdays(businessweek => 6, days => 8), tue->add(days => 9), "tue + 8 => thu (date) (6dw)"; -# same with substract +# same with subtract is mon->subtract_businessdays(days => 5)->day_of_week, 1, "mon - 5 => mon"; is mon->subtract_businessdays(days => 12)->day_of_week, 4, "mon - 12 => thu"; @@ -87,3 +90,17 @@ is sun->add_businessdays(days => 1), sun->add(days => 1), "1 day after sun is mo is sat->add_businessdays(days => 1), sat->add(days => 2), "1 day after sut is mon"; is sun->add_businessdays(days => -1), sun->add(days => -2), "1 day before sun is fri"; is sat->add_businessdays(days => -1), sat->add(days => -1), "1 day before sut is fri"; + +# parsing YYYY-MM-DD formatted strings +is(DateTime->from_ymd(), undef, "no argument results in undef"); +is(DateTime->from_ymd(''), undef, "empty argument results in undef"); +is(DateTime->from_ymd('chunky bacon'), undef, "invalid argument results in undef"); +is(DateTime->from_ymd('2014-06-23'), $mon_012345->clone->truncate(to => 'day'), "2014-06-23 is parsed correctly"); +is(DateTime->from_ymd('2014-06-23')->strftime('%H%M%S'), '000000', "2014-06-23 is parsed correctly"); + +# parsing YYYY-MM-DDTHH:MM:SS formatted strings +is(DateTime->from_ymdhms(), undef, "no argument results in undef"); +is(DateTime->from_ymdhms(''), undef, "empty argument results in undef"); +is(DateTime->from_ymdhms('chunky bacon'), undef, "invalid argument results in undef"); +is(DateTime->from_ymdhms('2014-06-23T01:23:45'), $mon_012345, "2014-06-23T01:23:45 is parsed correctly"); +is(DateTime->from_ymdhms('2014-06-23 01:23:45'), $mon_012345, "2014-06-23 01:23:45 is parsed correctly");