diff -urN DateTime-Format-ISO8601-0.0403.orig/lib/DateTime/Format/ISO8601.pm DateTime-Format-ISO8601-0.0403/lib/DateTime/Format/ISO8601.pm
--- DateTime-Format-ISO8601-0.0403.orig/lib/DateTime/Format/ISO8601.pm 2005-08-08 00:22:14.000000000 +0100
+++ DateTime-Format-ISO8601-0.0403/lib/DateTime/Format/ISO8601.pm 2007-01-21 11:53:59.000000000 +0000
@@ -963,6 +963,9 @@
if( defined $p{ parsed }{ day_of_year } ) {
$p{ parsed }{ week } -= $dt->day_of_week -1;
}
+ elsif( $dt->day_of_week == 1 ) {
+ $p{ parsed }{ week } += 1;
+ }
$p{ parsed }{ day_of_year } += $p{ parsed }{ week };
diff -urN DateTime-Format-ISO8601-0.0403.orig/t/02_examples.t DateTime-Format-ISO8601-0.0403/t/02_examples.t
--- DateTime-Format-ISO8601-0.0403.orig/t/02_examples.t 2005-08-08 00:22:14.000000000 +0100
+++ DateTime-Format-ISO8601-0.0403/t/02_examples.t 2007-01-20 20:28:26.000000000 +0000
@@ -9,7 +9,7 @@
use lib qw( ./lib );
-use Test::More tests => 175;
+use Test::More tests => 182;
use DateTime::Format::ISO8601;
@@ -275,6 +275,15 @@
is( $dt->week_number, '15' );
}
+# Each of these seven years has January 1st fall on a different day of the week
+for my $year (2007 .. 2012, 2014) {
+ my $base = DateTime->new( year => $year );
+ my $parser = DateTime::Format::ISO8601->new( base_datetime => $base );
+ my $dt = $parser->parse_datetime( '-W15' );
+ is( $dt->week_number, '15',
+ "parse correct week number from '-W15' in $year" );
+}
+
{
#-W-D -W-5
my $dt = DateTime::Format::ISO8601->parse_datetime( '-W-5' );