Subject: | truncate modifies original date when failing |
Date: | Tue, 25 Feb 2014 15:27:44 +0000 |
To: | bug-DateTime [...] rt.cpan.org |
From: | Vytautas D <vytdau [...] gmail.com> |
DateTime should not modify original object if it fails, consider this:
use DateTime;
use Test::More tests => 2;
my $dt = DateTime->new(
year => 2010,
month => 3,
day => 25,
hour => 1,
minute => 5,
time_zone => 'Asia/Tehran',
);
is(
$dt->day_of_week(),
'4',
'We start on Thursday'
);
eval {
$dt->truncate(to => 'week');
} || warn "Eval failed with '$@'\n";
is(
$dt->day_of_week(),
'4',
'should retain 4'
);
Output is:
1..2
ok 1 - We start on Thursday
Eval failed with 'Invalid local time for date in time zone: Asia/Tehran
'
not ok 2 - Should retain 4
# Failed test 'Should retain 4'
# got: '1'
# expected: '4'
# Looks like you failed 1 test of 2.