| 1 | package Time::DaysInMonth; | ||
| 2 | |||
| 3 | use Carp; | ||
| 4 | |||
| 5 | require 5.008001; | ||
| 6 | |||
| 7 | @ISA = qw(Exporter); | ||
| 8 | @EXPORT = qw(days_in is_leap); | ||
| 9 | @EXPORT_OK = qw(%mltable); | ||
| 10 | |||
| 11 | use strict; | ||
| 12 | |||
| 13 | use vars qw($VERSION %mltable); | ||
| 14 | |||
| 15 | $VERSION = 2026.0330; | ||
| 16 | |||
| 17 | CONFIG: { | ||
| 18 | %mltable = qw( | ||
| 19 | 1 31 | ||
| 20 | 3 31 | ||
| 21 | 4 30 | ||
| 22 | 5 31 | ||
| 23 | 6 30 | ||
| 24 | 7 31 | ||
| 25 | 8 31 | ||
| 26 | 9 30 | ||
| 27 | 10 31 | ||
| 28 | 11 30 | ||
| 29 | 12 31); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub days_in | ||
| 33 | { | ||
| 34 | # Month is 1..12 | ||
| 35 | my ($year, $month) = @_; | ||
| 36 | return $mltable{$month+0} unless $month == 2; | ||
| 37 | return 28 unless &is_leap($year); | ||
| 38 | return 29; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub is_leap | ||
| 42 | { | ||
| 43 | my ($year) = @_; | ||
| 44 | return 0 unless $year % 4 == 0; | ||
| 45 | return 1 unless $year % 100 == 0; | ||
| 46 | return 0 unless $year % 400 == 0; | ||
| 47 | return 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; | ||
| 51 | |||
| 52 | __END__ |