1use 5.008004; 2 3use strict; 4use warnings; 5 6use Test::More 0.88; # Because of done_testing(); 7use DateTime::Calendar::Christian; 8 9######################### 10 11sub test_dates { 12 my $r = DateTime->new( year => 1752, month => 9, day => 14 ); 13 foreach my $test ( @_ ) 14 { 15 my @args = @{ $test->[0] }; 16 my @results = @{ $test->[1] }; 17 18 my $dt = DateTime::Calendar::Christian->new( 19 year => $args[0], 20 month => $args[1], 21 day => $args[2], 22 reform_date => $r, 23 ); 24 25 my ($year, $week) = $dt->week(); 26 27 is( "$year-W$week", "$results[0]-W$results[1]", "woy @args" ); 28 } 29} 30 31# The week_number algorithm is different from the one in DateTime.pm, so 32# I include all its tests here. As there are no dates before 1752 here, 33# results should be the same. 34 35my @tests = ( [ [ 1964, 12, 31 ], [ 1964, 53 ] ], 36 [ [ 1965, 1, 1 ], [ 1964, 53 ] ], 37 [ [ 1971, 9, 7 ], [ 1971, 36 ] ], 38 [ [ 1971, 10, 25 ], [ 1971, 43 ] ], 39 [ [ 1995, 1, 1 ], [ 1994, 52 ] ], 40 [ [ 1995, 11, 18 ], [ 1995, 46 ] ], 41 [ [ 1995, 12, 31 ], [ 1995, 52 ] ], 42 [ [ 1996, 12, 31 ], [ 1997, 1 ] ], 43 [ [ 2001, 4, 28 ], [ 2001, 17 ] ], 44 [ [ 2001, 8, 2 ], [ 2001, 31 ] ], 45 [ [ 2001, 9, 11 ], [ 2001, 37 ] ], 46 [ [ 2002, 12, 25 ], [ 2002, 52 ] ], 47 [ [ 2002, 12, 31 ], [ 2003, 1 ] ], 48 [ [ 2003, 1, 1 ], [ 2003, 1 ] ], 49 [ [ 2003, 12, 31 ], [ 2004, 1 ] ], 50 [ [ 2004, 1, 1 ], [ 2004, 1 ] ], 51 [ [ 2004, 12, 31 ], [ 2004, 53 ] ], 52 [ [ 2005, 1, 1 ], [ 2004, 53 ] ], 53 [ [ 2005, 12, 31 ], [ 2005, 52 ] ], 54 [ [ 2006, 1, 1 ], [ 2005, 52 ] ], 55 [ [ 2006, 12, 31 ], [ 2006, 52 ] ], 56 [ [ 2007, 1, 1 ], [ 2007, 1 ] ], 57 [ [ 2007, 12, 31 ], [ 2008, 1 ] ], 58 [ [ 2008, 1, 1 ], [ 2008, 1 ] ], 59 [ [ 2008, 12, 31 ], [ 2009, 1 ] ], 60 [ [ 2009, 1, 1 ], [ 2009, 1 ] ], 61 ); 62 63test_dates( @tests ); 64 65@tests = ( [ [ 1751, 12, 29 ], [ 1751, 52 ] ], 66 [ [ 1751, 12, 30 ], [ 1752, 1 ] ], 67 [ [ 1752, 1, 1 ], [ 1752, 1 ] ], 68 [ [ 1752, 1, 5 ], [ 1752, 1 ] ], 69 [ [ 1752, 1, 6 ], [ 1752, 2 ] ], 70 [ [ 1752, 8, 30 ], [ 1752, 35 ] ], 71 [ [ 1752, 8, 31 ], [ 1752, 36 ] ], 72 [ [ 1752, 9, 2 ], [ 1752, 36 ] ], 73 [ [ 1752, 9, 14 ], [ 1752, 36 ] ], 74 [ [ 1752, 9, 17 ], [ 1752, 36 ] ], 75 [ [ 1752, 9, 18 ], [ 1752, 37 ] ], 76 [ [ 1752, 10, 26 ], [ 1752, 42 ] ], 77 [ [ 1752, 12, 24 ], [ 1752, 50 ] ], 78 [ [ 1752, 12, 25 ], [ 1752, 51 ] ], 79 [ [ 1752, 12, 31 ], [ 1752, 51 ] ], 80 [ [ 1753, 1, 1 ], [ 1753, 1 ] ], 81 ); 82 83test_dates( @tests ); 84 85done_testing; 86 87# ex: set textwidth=72 : 88