Saturday, 15 August 2015

perl - When doing math on DateTime objects near New Year's Eve, the utc_year field gets set weirdly. Is this a bug? -



perl - When doing math on DateTime objects near New Year's Eve, the utc_year field gets set weirdly. Is this a bug? -

i've found weird behavior perl datetim module. can seen below.

my $dt = datetime->new( year => 1950, month => 12, day => 31, hr => 21, min => 0, sec => 0, time_zone => "america/new_york", ); print "utc year: " . $dt->utc_year . "\n"; print "utc seconds: " . $dt->{utc_rd_secs} . "\n"; $dt->add(minutes => 1); print "utc year: " . $dt->utc_year . "\n"; print "utc seconds: " . $dt->{utc_rd_secs} . "\n";

the output of script is:

utc year: 1951 utc seconds: 7200 utc year: 1952 utc seconds: 7260

so somehow adding 1 min date 12/31/1950 21:00 'new york' results in year jumping way 1952. think bug, wanted see if had other ideas.

let's check documentation see utc_year returns... oh wait, it's not documented! makes rather hard determine it's returning wrong thing, doesn't it?

as can surmise finish lack of mention in datetime's extensive documentation, it's internal method. it's used exchange info datetime::timezone objects. returns rough guess of datetime's year according comments within.

if want dt in different time zone (e.g. utc), utilize ->set_time_zone.

perl datetime

No comments:

Post a Comment