File Coverage

blib/lib/Date/Advent.pm
Criterion Covered Total %
statement 38 38 100.0
branch 4 4 100.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 1 1 100.0
total 53 53 100.0


line stmt bran cond sub pod time code
1             package Date::Advent;
2              
3 2     2   105255 use v5.22;
  2         5  
4 2     2   997 use Moose;
  2         592921  
  2         9  
5              
6 2     2   9060 use Carp;
  2         10  
  2         125  
7 2     2   667 use Time::Piece;
  2         6963  
  2         11  
8 2     2   1148 use Date::Lectionary::Time qw(nextSunday prevSunday);
  2         4428  
  2         99  
9 2     2   886 use namespace::autoclean;
  2         10634  
  2         5  
10              
11             =head1 NAME
12              
13             Date::Advent - Calculate the Sundays of Advent
14              
15             =head1 VERSION
16              
17             Version 1.20161222
18              
19             =cut
20              
21             our $VERSION = '1.20161222';
22              
23             =head1 SYNOPSIS
24              
25             Date::Advent takes a Time::Piece date and calculates all four Sundays of Advent for the current Christian liturgical year.
26              
27             As Advent is the beginning of the Christian liturgical calendar, this usually results in the date for Advent in the current year being dates in the past. E.g. The Sundays of Advent returned for 12. March 2016 would be 29. November 2015, 6. December 2015, 13. December 2015, and 20. December 2015.
28              
29             use Time::Piece;
30             use Date::Advent;
31              
32             my $testAdvent = Date::Advent->new(date => Time::Piece->strptime("2016-01-01", "%Y-%m-%d"));
33             say $testAdvent->firstSunday; #Gives date for first Sunday of Advent
34             say $testAdvent->secondSunday; #Gives date for second Sunday of Advent
35             say $testAdvent->thirdSunday; #Gives date for third Sunday of Advent
36             say $testAdvent->fourthSunday; #Gives date for fourth Sunday of Advent
37             say $testAdvent->christmas; #Gives date of Christmas
38              
39             The development of this module is hosted on GitHub -- L<https://github.com/marmanold/Date-Advent> -- and tested via TravisCI.
40              
41             =for html <a href='https://travis-ci.org/marmanold/Date-Advent'><img src='https://travis-ci.org/marmanold/Date-Advent.svg?branch=master' /></a>
42              
43             =for html <a href='https://coveralls.io/github/marmanold/Date-Advent?branch=master'><img src='https://coveralls.io/repos/github/marmanold/Date-Advent/badge.svg?branch=master' alt='Coverage Status' /></a>
44              
45             =head1 Object Attributes
46              
47             =head2 date
48              
49             Time::Piece date object. Only attribute required at object construction.
50              
51             =head2 christmas
52              
53             Time::Piece attribute for Christmas Day as calculated from the C<date> given at object construction.
54              
55             =head2 firstSunday
56              
57             Time::Piece attribute for the first Sunday of Advent as calculated from the C<date> given at object construction.
58              
59             =head2 secondSunday
60              
61             Time::Piece attribute for the second Sunday of Advent as calculated from the C<date> given at object construction.
62              
63             =head2 thirdSunday
64              
65             Time::Piece attribute for the third Sunday of Advent as calculated from the C<date> given at object construction.
66              
67             =head2 fourthSunday
68              
69             Time::Piece attribute for the fourth Sunday of Advent as calculated from the C<date> given at object construction.
70              
71             =cut
72              
73             has 'date' => (
74             is => 'ro',
75             isa => 'Time::Piece',
76             );
77              
78             has 'christmas' => (
79             is => 'ro',
80             isa => 'Time::Piece',
81             init_arg => undef,
82             writer => '_setChristmas',
83             );
84              
85             has 'firstSunday' => (
86             is => 'ro',
87             isa => 'Time::Piece',
88             init_arg => undef,
89             writer => '_setFirstSunday',
90             );
91              
92             has 'secondSunday' => (
93             is => 'ro',
94             isa => 'Time::Piece',
95             init_arg => undef,
96             writer => '_setSecondSunday',
97             );
98              
99             has 'thirdSunday' => (
100             is => 'ro',
101             isa => 'Time::Piece',
102             init_arg => undef,
103             writer => '_setThirdSunday',
104             );
105              
106             has 'fourthSunday' => (
107             is => 'ro',
108             isa => 'Time::Piece',
109             init_arg => undef,
110             writer => '_setFourthSunday',
111             );
112              
113             =head1 Object Constructor
114              
115             =head2 BUILD
116              
117             Constructor for the Date::Advent object. Takes the Time::Piece argument of C<date> as the date to calculate the current Christian liturgical year's Sundays of Advent from. The resulting object is immutable and cannot be changed once created.
118              
119             my $testAdvent = Date::Advent->new(date => Time::Piece->strptime("2016-01-01", "%Y-%m-%d"));
120              
121             =cut
122              
123             sub BUILD {
124 4     4 1 4 my $self = shift;
125              
126 4         3 my $xmasYear;
127 4 100 100     92 if ( $self->date->mon == 11 || $self->date->mon == 12 ) {
128 3         69 $xmasYear = $self->date->year;
129             }
130             else {
131 1         25 $xmasYear = $self->date->year - 1;
132             }
133              
134 4         22 my $christmasDay = Time::Piece->strptime( "$xmasYear-12-25", "%Y-%m-%d" );
135              
136 4         144 my $fourthAdvent = prevSunday($christmasDay);
137 4         418 my $thirdAdvent = prevSunday($fourthAdvent);
138 4         309 my $secondAdvent = prevSunday($thirdAdvent);
139 4         293 my $firstAdvent = prevSunday($secondAdvent);
140              
141 4 100       409 if ( $self->date < $firstAdvent ) {
142 2         30 $christmasDay = $christmasDay->add_years(-1);
143              
144 2         114 $fourthAdvent = prevSunday($christmasDay);
145 2         159 $thirdAdvent = prevSunday($fourthAdvent);
146 2         145 $secondAdvent = prevSunday($thirdAdvent);
147 2         142 $firstAdvent = prevSunday($secondAdvent);
148             }
149              
150 4         276 $self->_setChristmas($christmasDay);
151 4         101 $self->_setFirstSunday($firstAdvent);
152 4         99 $self->_setSecondSunday($secondAdvent);
153 4         160 $self->_setThirdSunday($thirdAdvent);
154 4         109 $self->_setFourthSunday($fourthAdvent);
155             }
156              
157             =head1 AUTHOR
158              
159             Michael Wayne Arnold, C<< <marmanold at cpan.org> >>
160              
161             =head1 BUGS
162              
163             Please report any bugs or feature requests to C<bug-date-advent at rt.cpan.org>, or through
164             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Date-Advent>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
165              
166             =head1 SUPPORT
167              
168             You can find documentation for this module with the perldoc command.
169              
170             perldoc Date::Advent
171              
172              
173             You can also look for information at:
174              
175             =over 4
176              
177             =item * RT: CPAN's request tracker (report bugs here)
178              
179             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Date-Advent>
180              
181             =item * AnnoCPAN: Annotated CPAN documentation
182              
183             L<http://annocpan.org/dist/Date-Advent>
184              
185             =item * CPAN Ratings
186              
187             L<http://cpanratings.perl.org/d/Date-Advent>
188              
189             =item * Search CPAN
190              
191             L<http://search.cpan.org/dist/Date-Advent/>
192              
193             =back
194              
195              
196             =head1 ACKNOWLEDGEMENTS
197              
198             Many thanks to my beautiful wife, Jennifer, and my amazing daughter, Rosemary. But, above all, SOLI DEO GLORIA!
199              
200             =head1 LICENSE AND COPYRIGHT
201              
202             Copyright 2016 Michael Wayne Arnold.
203              
204             This program is free software; you can redistribute it and/or modify it
205             under the terms of either: the GNU General Public License as published
206             by the Free Software Foundation; or the Artistic License.
207              
208             See L<http://dev.perl.org/licenses/> for more information.
209              
210              
211             =cut
212              
213             __PACKAGE__->meta->make_immutable;
214              
215             1; # End of Date::Advent