SBECK-github / Date-Manip

Other
10 stars 11 forks source link

Wrong Year for leap week #35

Closed jkowalke closed 3 years ago

jkowalke commented 3 years ago

Hi, i believe to have found a bug regarding the year in a leap week. In my example I'm getting the current year and not the last one. In my opinion it should be the last year for the weak 53.

Code:

use Date::Manip;
use Data::Dumper;

my $date = &ParseDateString("2021-01-03");
print Dumper UnixDate($date, "%Y%W");

Result:

$VAR1 = '202153';

Expected Result:

$VAR1 = '202053';

Date::Manip-Version: 6.60 [europe/berlin]

Perl Version: This is perl 5, version 26, subversion 3 (v5.26.3) built for x86_64-linux-thread-multi (with 51 registered patches)

SBECK-github commented 3 years ago

The '%Y' value is the year of the date, which is 2021. If you read the manual, you'll see:

      Special Year/Week formats (see NOTE 2 below)
          %G     year, Monday as first
                 day of week              - 0001 to 9999
          %W     week of year, Monday
                 as first day of week     - 01 to 53

%G is the format you need to use to print the year that corresponds to %W. Note 2 in the documentation explains this fully, so I'd suggest you read that for a complete understanding.

If you prrint "%G%W", you will get your expected result.

jkowalke commented 3 years ago

Thank you very much