| 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.0219; |
| 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__ |
| 53 |
|
| 54 |
=head1 NAME |
| 55 |
|
| 56 |
Time::DaysInMonth -- simply report the number of days in a month |
| 57 |
|
| 58 |
=head1 SYNOPSIS |
| 59 |
|
| 60 |
use Time::DaysInMonth; |
| 61 |
$days = days_in($year, $month_1_to_12); |
| 62 |
$leapyear = is_leap($year); |
| 63 |
|
| 64 |
=head1 DESCRIPTION |
| 65 |
|
| 66 |
DaysInMonth is simply a package to report the number of days in |
| 67 |
a month. That's all it does. Really! |
| 68 |
|
| 69 |
=head1 AUTHOR |
| 70 |
|
| 71 |
Best Practical Solutions, LLC E<lt>[email protected]<gt> |
| 72 |
|
| 73 |
=head1 ORIGINAL AUTHOR |
| 74 |
|
| 75 |
David Muir Sharnoff |
| 76 |
|
| 77 |
=head1 BUGS |
| 78 |
|
| 79 |
This only deals with the "modern" calendar. Look elsewhere for |
| 80 |
historical time and date support. |
| 81 |
|
| 82 |
=head1 LICENSE AND COPYRIGHT |
| 83 |
|
| 84 |
Copyright (C) 1996-1999 David Muir Sharnoff. |
| 85 |
Copyright (C) 2026 Best Practical Solutions, LLC. |
| 86 |
|
| 87 |
This library is free software; you can redistribute it and/or modify |
| 88 |
it under the same terms as Perl itself. |
| 89 |
|