Subject: | strftime specifiers %U and %W do not work as advertised |
The documentation implies that strftime pads the values generated by
%U and %W with zeros to two decimal places. However, padding is
only done to the %V specifier.
The relevant code (DateTime.pm line 889):
'U' => sub { my $dow = $_[0]->day_of_week;
$dow = 0 if $dow == 7; # convert to 0-6, Sun-Sat
my $doy = $_[0]->day_of_year - 1;
return int( ( $doy - $dow + 13 ) / 7 - 1 )
},
'V' => sub { sprintf( '%02d', $_[0]->week_number ) },
'w' => sub { my $dow = $_[0]->day_of_week;
return $dow % 7;
},
'W' => sub { my $dow = $_[0]->day_of_week;
my $doy = $_[0]->day_of_year - 1;
return int( ( $doy - $dow + 13 ) / 7 - 1 )
},
To match the documentation, this should be:
'U' => sub { my $dow = $_[0]->day_of_week;
$dow = 0 if $dow == 7; # convert to 0-6, Sun-Sat
my $doy = $_[0]->day_of_year - 1;
my $wn = int( ( $doy - $dow + 13 ) / 7 - 1 );
return sprintf( '%02d', $wn);
},
'V' => sub { sprintf( '%02d', $_[0]->week_number ) },
'w' => sub { my $dow = $_[0]->day_of_week;
return $dow % 7;
},
'W' => sub { my $dow = $_[0]->day_of_week;
my $doy = $_[0]->day_of_year - 1;
my $wn = int( ( $doy - $dow + 13 ) / 7 - 1 );
return sprintf( '%02d', $wn);
},