line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Header: /home/cvs/date-doomsday/lib/Date/DayOfWeek.pm,v 1.22 2003/02/02 13:40:37 rbowen Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Date::DayOfWeek; |
4
|
2
|
|
|
2
|
|
48083
|
use Date::Doomsday qw(); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
42
|
|
5
|
2
|
|
|
2
|
|
2100
|
use Date::Leapyear qw(); |
|
2
|
|
|
|
|
492
|
|
|
2
|
|
|
|
|
36
|
|
6
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
108
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
2
|
|
|
2
|
|
10
|
use vars qw( @ISA @EXPORT $VERSION ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
382
|
|
10
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@EXPORT = qw( dayofweek ); |
13
|
|
|
|
|
|
|
$VERSION = ( qw($Revision: 1.22 $) )[1]; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Docs {{{ |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Date::DayOfWeek - Determine the day of the week for any date. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Date::DayOfWeek; |
24
|
|
|
|
|
|
|
$dow = dayofweek( 25, 10, 1971 ); # dd, mm, yyyy |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Calculates the day of the week for any date in the Gregorian calendar |
29
|
|
|
|
|
|
|
(1563 and following). |
30
|
|
|
|
|
|
|
Based on the Doomsday algorithm of John Conway. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#}}} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# sub dayofweek {{{ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 dayofweek |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$dow = dayofweek( 25, 10, 1971 ); |
41
|
|
|
|
|
|
|
$dow = dayofweek( 4, 7, 1776 ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Returns the day of the week for any date between 1500 and 2699. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Month should be in the range 1..12 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
The day of week that is returned is an integer in the range 0..6, with 0 = |
48
|
|
|
|
|
|
|
sunday, 1 = monday, etc. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub dayofweek { |
53
|
21
|
|
|
21
|
0
|
49
|
my ($day, $month, $year) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# When is doomsday this year? |
56
|
21
|
|
|
|
|
66
|
my $doomsday = Date::Doomsday::doomsday( $year ); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# And when is doomsday this month? |
59
|
|
|
|
|
|
|
|
60
|
21
|
|
|
|
|
224
|
my @base = ( 0, 0, 7, 4, 9, 6, 11, 8, 5, 10, 7, 12 ); |
61
|
21
|
100
|
|
|
|
501
|
@base[0,1] = Date::Leapyear::isleap($year) ? (32,29) : (31,28); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# And how far after that are we? |
64
|
21
|
|
|
|
|
189
|
my $on = $day - $base[$month - 1]; |
65
|
21
|
|
|
|
|
23
|
$on = $on % 7; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# So, the day of the week should be doomsday, plus however far on we are |
68
|
21
|
|
|
|
|
115
|
return ($doomsday + $on) % 7; |
69
|
|
|
|
|
|
|
} # }}} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Rich Bowen (rbowen@rcbowen.com) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 See Also |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Date::Doomsday |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Date::DayOfWeek::Birthday, Date::DayOfWeek::Nails, and |
80
|
|
|
|
|
|
|
Date::DayOfWeek::Birthday |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Date::Christmas |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# CVS history {{{ |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 HISTORY |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$Log: DayOfWeek.pm,v $ |
91
|
|
|
|
|
|
|
Revision 1.22 2003/02/02 13:40:37 rbowen |
92
|
|
|
|
|
|
|
Change link in documentation. Other minor cosmetic changes. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Revision 1.21 2001/12/22 01:28:54 rbowen |
95
|
|
|
|
|
|
|
Documentation updates. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Revision 1.20 2001/10/10 02:35:07 rbowen |
98
|
|
|
|
|
|
|
Bug reported by Francois Claveau. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Revision 1.19 2001/08/25 21:28:14 rbowen |
101
|
|
|
|
|
|
|
Moved files to lib directory |
102
|
|
|
|
|
|
|
Removed 5.6 dependencies. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Revision 1.18 2001/08/03 04:24:39 rbowen |
105
|
|
|
|
|
|
|
Alter locations of modules - moved into Date subdir. |
106
|
|
|
|
|
|
|
Added to MANIFEST |
107
|
|
|
|
|
|
|
No longer reqiure 5.005_62. Not sure why that was there. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Revision 1.17 2001/06/11 01:49:05 rbowen |
110
|
|
|
|
|
|
|
Additional docs. Added Sneeze.pm |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Revision 1.16 2001/06/10 18:46:03 rbowen |
113
|
|
|
|
|
|
|
Moved isleap functionality into Date::Leapyear. Added Birthday.pm and |
114
|
|
|
|
|
|
|
Nails.pm as examples of the strange things that people believe - or |
115
|
|
|
|
|
|
|
believed a few hundred years ago, with regard to days of the week. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Revision 1.15 2001/06/06 02:29:14 rbowen |
118
|
|
|
|
|
|
|
Added some more doomsday tests. Removed dayofweek tests that referred |
119
|
|
|
|
|
|
|
to years before the Gregorian calendar. Extended the range of |
120
|
|
|
|
|
|
|
Doomsday.pm indefinately into the future. And a small bug fix in |
121
|
|
|
|
|
|
|
DayOfWeek.pm |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Revision 1.14 2001/06/06 01:41:45 rbowen |
124
|
|
|
|
|
|
|
Made the calculation a little more elegant, if somewhat less |
125
|
|
|
|
|
|
|
informative. Thanks for patch from Jerrad Pierce. Thanks for |
126
|
|
|
|
|
|
|
various suggestions from David Pitts. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Revision 1.13 2001/05/27 19:34:46 rbowen |
129
|
|
|
|
|
|
|
Rearranged argument order. day month year makes more sense. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Revision 1.12 2001/05/27 03:44:03 rbowen |
132
|
|
|
|
|
|
|
Need to mod return value by 7. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Revision 1.11 2001/05/27 03:41:31 rbowen |
135
|
|
|
|
|
|
|
This seems to work on all the dates that I've tested it for. More testing is |
136
|
|
|
|
|
|
|
needed. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Revision 1.10 2001/05/27 03:13:57 rbowen |
139
|
|
|
|
|
|
|
Add DayOfWeek to repository. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# }}} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|