########################################################################### # # day_of_week($year, $month, $day) # # Valid from 14 September 1752 onwards. $month and $day are 1 indexed. # # Returns: 0 .. 6 where 0 is Sunday. # # Algorithm by Tomohiko Sakamoto from the C FAQ, section 20.31. # sub day_of_week { my ($year, $month, $day) = @_; my @offset = (0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4); $year -= $month < 3; return ($year + int($year/4) - int($year/100) + int($year/400) + $offset[$month-1] + $day) % 7; }