File Coverage

blib/lib/Date/SundayLetter.pm
Criterion Covered Total %
statement 33 33 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 0 3 0.0
total 43 46 93.4


line stmt bran cond sub pod time code
1             #$Header: /home/cvs/date-sundayletter/lib/Date/SundayLetter.pm,v 1.10 2002/08/29 23:33:13 rbowen Exp $
2             package Date::SundayLetter;
3 3     3   87188 use Date::Leapyear;
  3         856  
  3         155  
4 3     3   14 use strict;
  3         7  
  3         154  
5              
6             BEGIN {
7 3     3   16 use Exporter ();
  3         11  
  3         74  
8 3     3   17 use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  3         5  
  3         374  
9 3     3   7 $VERSION = (qw'$Revision: 1.10 $')[1];
10 3         197 @ISA = qw (Exporter);
11             #Give a hoot don't pollute, do not export more than needed by default
12 3         10 @EXPORT = qw (sundayletter letter);
13 3         5 @EXPORT_OK = qw ();
14 3         1690 %EXPORT_TAGS = ();
15             }
16              
17             # Documentation {{{
18              
19             =head1 NAME
20              
21             Date::SundayLetter - Calculates the Sunday Letters for a given year
22              
23             =head1 SYNOPSIS
24              
25             use Date::SundayLetter;
26             $letter = sundayletter( 1996 );
27              
28             - or just -
29              
30             $letter = letter( 1996 );
31              
32             =head1 DESCRIPTION
33              
34             Sunday Letters are an important concept from calendrics. Stated very
35             simply, the sunday letter represents how many days after January 1 the
36             first Sunday of the year is. Knowing the makes it easy to calculate
37             the day of the week of a given day, when Easter falls, and a variety
38             of other things.
39              
40             There is a full treatment of Sunday Latters in The Oxford Companion to
41             the Year (Blackburn, Holford-Strevens).
42              
43             For example, the following table shows the Sunday Letters, given the
44             day of the week of January 1:
45              
46             1 January First Sunday Sunday Letter
47             Sunday 1 January A
48             Monday 7 January G
49             Tuesday 6 January F
50             Wednesday 5 January E
51             Thursday 4 January D
52             Friday 3 January C
53             Saturday 2 January B
54              
55             In leap years, you have two Sunday Letters. After leap day, you have a
56             Sunday Letter calculated with the usual formulae. Before leap day, the
57             Sunday Letter is one place ahead of that (with A being considered one
58             latter after G).
59              
60             Given the Sunday Letter and the Golden Number (see
61             Date::GoldenNumber), you can immediately look up the dates for Easter
62             (Gregorian or Julian) in a simple table. That is, if you happen to
63             have said table. I'll try to put this table on my web site, but I need
64             to ask the authors of The Oxford Companion first.
65              
66             =head1 SUPPORT
67              
68             For support, email me directly (drbacchus@drbacchus.com) or subscribe
69             to datetime@perl.org (see http://lists.perl.org/ for subscription
70             information) and ask there.
71              
72             =head1 AUTHOR
73              
74             Rich Bowen
75             CPAN ID: RBOW
76             rbowen@rcbowen.com
77             http://www.rcbowen.com
78              
79             =head1 COPYRIGHT
80              
81             Copyright (c) 2001 Rich Bowen. All rights reserved.
82             This program is free software; you can redistribute
83             it and/or modify it under the same terms as Perl itself.
84              
85             The full text of the license can be found in the
86             LICENSE file included with this module.
87              
88             =head1 SEE ALSO
89              
90             perl(1).
91             Date::ICal
92             Reefknot (http://reefknot.org/)
93             Date::Easter
94             Date::Passover
95             Date::Leapyear
96              
97             =cut
98              
99             # }}}
100              
101             # sub sundayletter {{{
102              
103 10     10 0 65 sub letter { return sundayletters(@_) }
104              
105             sub sundayletters {
106 10     10 0 12 my $year = shift;
107            
108 10         26 my @letters = qw(A G F E D C B);
109              
110 10         21 my $p = parameter($year);
111              
112 10         15 my $q = int($year / 4); # divide by 4, discard remainder
113 10         11 my $t = $year + $q + $p; # Add quotient to year, and add
114             # the parameter.
115 10         12 my $d = $t % 7; # Remainder when divided by 7 gives the
116             # displacement from January 1 to the first Sunday
117             # of the year.
118              
119 10         36 my $letter;
120 10 100       46 if (Date::Leapyear::isleap( $year )) {
121 4         31 $letter = $letters[$d-1] . $letters[$d] ;
122             } else {
123 6         45 $letter = $letters[$d];
124             }
125              
126 10         54 return $letter;
127             } #}}}
128              
129             # sub parameter {{{
130              
131             sub parameter {
132             # The "parameter" is a magic number that tracks how far the Gregorian
133             # calendar is from the Julian calendar. It has roughly to do with the
134             # fact that the Gregorian calendar observes leap year on the 4-century
135             # mark, and the Julian calendar does not.
136 15     15 0 29 my $year = shift;
137              
138 15         33 my $S = int ($year / 100 );
139 15         32 my $P = ( int( $S/4 ) - $S ) % 7;
140              
141 15         37 return $P;
142             } # }}}
143              
144             1;
145              
146