Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 11621
Status: resolved
Priority: 0/
Queue: DateTime

People
Owner: DROLSKY [...] cpan.org
Requestors: jdocauer [...] fedex.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.27
Fixed in: 0.28



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); },