atoomic / perl-TimeDate

time & date parsing and formatting perl library
http://search.cpan.org/dist/TimeDate/
1 stars 3 forks source link

str2time wrong date when no year specified [rt.cpan.org #92611] #15

Open atoomic opened 4 years ago

atoomic commented 4 years ago

Migrated from rt.cpan.org#92611 (status was 'new')

Requestors:

From honir999@gmail.com on 2014-01-31 10:31:24 :

Parsing dates when no year specified, for a future month generates wrong year.

perl -e "use Date::Parse; print str2time('31 Jan');"

1391126400

i.e. Fri, 31 Jan 2014 00:00:00 GMT

but 

perl -e "use Date::Parse; print str2time('1 Feb');"

1359676800

i.e. Fri, 01 Feb 2013 00:00:00 GMT

Wrong year: expected output 1391212800 i.e. Sat, 01 Feb 2014 00:00:00 GMT

Code causing the error is line 252, which is always subtracting 1 from the year for a future month when the year is undefined.

$year = ($month > $lt[4]) ? ($lt[5] - 1) : $lt[5]
  unless(defined $year);

Date::Parse 2.30
perl, v5.8.8