1Date::Calendar::ProfileUss(e3r)Contributed Perl DocumentDaattieo:n:Calendar::Profiles(3)
2
3
4

NAME

6       Date::Calendar::Profiles - Some sample profiles for Date::Calendar and
7       Date::Calendar::Year
8

SYNOPSIS

10         use Date::Calendar::Profiles qw( $Profiles );
11         use Date::Calendar;
12
13         $cal_US_AK = Date::Calendar->new( $Profiles->{'US-AK'} [,LANG] );
14         $cal_DE_BY = Date::Calendar->new( $Profiles->{'DE-BY'} [,LANG] );
15
16        or
17
18         use Date::Calendar::Profiles qw( $Profiles );
19         use Date::Calendar::Year;
20
21         $year_2000_US_FL = Date::Calendar::Year->new( 2000, $Profiles->{'US-FL'} [,LANG] );
22         $year_2001_DE_NW = Date::Calendar::Year->new( 2001, $Profiles->{'DE-NW'} [,LANG] );
23
24        and also
25
26         use Date::Calendar::Profiles
27         qw(
28             &Previous_Friday
29             &Next_Monday
30             &Next_Monday_or_Tuesday
31             &Nearest_Workday
32             &Sunday_to_Monday
33             &Advent1
34             &Advent2
35             &Advent3
36             &Advent4
37             &Advent
38         );
39

PREFACE

41       This module provides some sample profiles (i.e., holiday schemes) for
42       use with the Date::Calendar(3) and Date::Calendar::Year(3) module.
43
44       You are not required to use these, you can always roll your own (this
45       is very easy). See the section "HOW TO ROLL YOUR OWN" below for more
46       instructions on how to do this, and take the profiles from this module
47       as examples.
48
49       Please let me know of any errors in these profiles, and please send me
50       your own profiles if you'd like to see them included in the next
51       release of this module! Thank you!
52
53       (But please, only use the ISO-Latin-1 character set whenever possible,
54       since my module doesn't support any other character sets yet, or at
55       least tell me which character set you used so I can document this in
56       this manual page. Thank you!)
57

DESCRIPTION

59       The method "init()" in module Date::Calendar::Year(3) is responsible
60       for parsing the calendar schemes contained here in the Date::Calen‐
61       dar::Profiles module.
62
63       This method offers a "mini-language" which allows to specify common
64       date formulas, like for instance a simple fixed date (in various dif‐
65       ferent formats, e.g. american or european), or things like "the second
66       Sunday of May" (Mother's Day), or "Easter Sunday minus 46 days" (Ash
67       Wednesday), to cite just a few.
68
69       See the section "DATE FORMULA SYNTAX" below for more details.
70
71       There are some more complicated formulas, however, which cannot be
72       expressed in such simple terms.
73
74       The rule that if a holiday falls on a weekend, it will be substituted
75       by either the adjacent Friday or Monday (whichever lies closer), is an
76       example of this.
77
78       In order to be able to deal with such formulas, and in order to be as
79       flexible as possible, the "init()" method offers the possibility of
80       using callback functions to deal with such dates and formulas.
81
82       See the section "CALLBACK INTERFACE" below for more details on this
83       topic.
84
85       In order to assist you with more common cases of odd formulas, the mod‐
86       ule Date::Calendar::Profiles exports the following utility subroutines
87       (which are meant to be used as "filters" in callback functions of your
88       own):
89
90       · "($year,$month,$day[,ANYTHING]) = Previous_Fri‐
91         day($year,$month,$day[,ANYTHING]);"
92
93         If the given date falls on a Saturday or Sunday, this function
94         changes the date to the adjacent Friday before that, and returns this
95         new date.
96
97         Otherwise the given date is returned unchanged.
98
99         The rest of the input parameters, if any, are simply copied to the
100         output.
101
102       · "($year,$month,$day[,ANYTHING]) = Next_Monday($year,$month,$day[,ANY‐
103         THING]);"
104
105         If the given date falls on a Saturday or Sunday, this function
106         changes the date to the adjacent Monday after that, and returns this
107         new date.
108
109         Otherwise the given date is returned unchanged.
110
111         The rest of the input parameters, if any, are simply copied to the
112         output.
113
114       · "($year,$month,$day[,ANYTHING]) = Next_Monday_or_Tues‐
115         day($year,$month,$day[,ANYTHING]);"
116
117         If the given date falls on a Saturday, the date of the next Monday
118         (after that weekend) is returned.
119
120         If the given date falls on a Sunday, the date of the next Tuesday
121         (after that weekend) is returned.
122
123         If the given date falls on a Monday, the date of the next Tuesday
124         (the day after the Monday) is returned.
125
126         Otherwise the given date is returned unchanged.
127
128         The rest of the input parameters, if any, are simply copied to the
129         output.
130
131         This function is used for the second of two adjacent holidays, where
132         the first holiday obeys the "Next Monday" rule (see the description
133         of the function immediately above).
134
135         Examples of this are Christmas and Boxing Day, among others.
136
137         When the first holiday falls on Friday, the second one falls on Sat‐
138         urday and is substituted by Monday.
139
140         When the first holiday falls on a Saturday, the second one falls on
141         Sunday, so the first holiday is substituted by Monday and the second
142         one by Tuesday.
143
144         When the first holiday falls on a Sunday, the second one falls on a
145         Monday. Therefore the first holiday is substituted by Monday, and
146         consequently the second holiday must be substituted by Tuesday.
147
148         Or, in other terms:
149
150             Fri Sat => Fri Mon
151             Sat Sun => Mon Tue
152             Sun Mon => Mon Tue
153
154         Note that there is no filter subroutine yet for the second of two
155         adjacent holidays when the first holiday obeys the "Nearest Workday"
156         rule (see the function described immediately below), i.e.,
157
158             Fri Sat => Fri Mon
159             Sat Sun => Fri Mon
160             Sun Mon => Mon Tue
161
162         This is left as an excercise to the inclined reader. ":-)"
163
164       · "($year,$month,$day[,ANYTHING]) = Nearest_Work‐
165         day($year,$month,$day[,ANYTHING]);"
166
167         If the given date falls on a Saturday, this function returns the date
168         of the Friday on the day before.
169
170         If the given date falls on a Sunday, this function returns the date
171         of the Monday on the day after.
172
173         Otherwise the given date is returned unchanged.
174
175         The rest of the input parameters, if any, are simply copied to the
176         output.
177
178       · "($year,$month,$day[,ANYTHING]) = Sunday_to_Mon‐
179         day($year,$month,$day[,ANYTHING]);"
180
181         If the given date falls on a Sunday, this function returns the date
182         of the Monday on the day after.
183
184         Otherwise the given date is returned unchanged.
185
186         The rest of the input parameters, if any, are simply copied to the
187         output.
188
189       The typical use of these filter subroutines is in a "return" statement
190       at the end of callback functions of your own, when you already have
191       calculated the holiday in question and only need to adjust it according
192       to the rule implemented by the filter subroutine in question.
193
194       See also the implementation of the Date::Calendar::Profiles module for
195       examples of how to use these functions.
196

DATE FORMULA SYNTAX

198        -  Fixed dates:
199
200           "Christmas"  =>  "24.12",   # European format (day, month)
201           "Christmas"  =>  "24.12.",
202
203           "Christmas"  =>  "24Dec",
204           "Christmas"  =>  "24.Dec",
205           "Christmas"  =>  "24Dec.",
206           "Christmas"  =>  "24.Dec.",
207
208           "Christmas"  =>  "24-12",
209           "Christmas"  =>  "24-12-",
210
211           "Christmas"  =>  "24-Dec",
212           "Christmas"  =>  "24-Dec-",
213
214           "Christmas"  =>  "12/25",   # American format (month, day)
215           "Christmas"  =>  "Dec25",
216           "Christmas"  =>  "Dec/25",
217
218        -  Dates relative to Easter Sunday:
219
220           "Ladies' Carnival"  =>  "-52",
221           "Carnival Monday"   =>  "-48",
222           "Mardi Gras"        =>  "-47",
223           "Ash Wednesday"     =>  "-46",
224           "Palm Sunday"       =>   "-7",
225           "Maundy Thursday"   =>   "-3",
226           "Good Friday"       =>   "-2",
227           "Easter Sunday"     =>   "+0",
228           "Easter Monday"     =>   "+1",
229           "Ascension"         =>  "+39",
230           "Whitsunday"        =>  "+49",
231           "Whitmonday"        =>  "+50",
232           "Corpus Christi"    =>  "+60",
233
234        -  The 1st, 2nd, 3rd, 4th or last day of week:
235
236           "Thanksgiving"      =>  "4Thu11",
237           "Thanksgiving"      =>  "4/Thu/Nov",
238           "Columbus Day"      =>  "2/Mon/Oct",
239           "Columbus Day"      =>  "2/Mon/10",
240           "Columbus Day"      =>  "2/1/Oct",
241           "Columbus Day"      =>  "2/1/10",
242           "Memorial Day"      =>  "5/Mon/May", # LAST Monday of May
243
244        -  Half holidays, commemorative days:
245
246           "Christmas"         =>  ":24.12.", # only half a day off
247           "Valentine's Day"   =>  "#Feb/14", # not an official holiday
248

CALLBACK INTERFACE

250       The interface of the callback functions to use with the "init()" method
251       of the Date::Calendar::Year(3) module is very simple:
252
253       The callback function receives two arguments when called, first the
254       year number for which the holiday is to be calculated, and second the
255       name (the "label") of the holiday in question (which serves as key in
256       the hash of a holiday scheme).
257
258       This second parameter allows you to use the same callback function for
259       different holidays, which might be more practical (than separate call‐
260       back functions) if for instance you have a set of similar holidays to
261       calculate, like for instance the four Sundays before Christmas
262       ("Advent").
263
264       The callback function "Advent()" (exported by the Date::Calendar::Pro‐
265       files module) exemplifies this technique.
266
267       The callback function is expected to return a list
268       ""($year,$month,$day)"" with the exact date of the holiday (the year
269       number in the output must of course match the year number passed as
270       parameter).
271
272       A fatal error occurs if the returned list does not constitute a valid
273       date, in the requested year.
274
275       Optionally, the callback function may return a fourth value (after the
276       date) containing a string, which may be either "#" or ":".
277
278       The string "#" signifies that the date in question is a purely commemo‐
279       rative date, i.e., that you don't get a day off from work on that day.
280
281       The string ":" means that the date in question is a "half" holiday,
282       i.e., a day on which you get half a day off from work.
283
284       In case the holiday in question was not observed or did not exist in
285       the requested year, the callback function may also return an empty
286       list. This will cause the "init()" method to simply drop this holiday
287       for that year.
288
289       The module Date::Calendar::Profiles exports the sample callback func‐
290       tions "Advent1()", "Advent2()", "Advent3()", "Advent4()" and
291       "Advent()", which might assist you in rolling your own profiles.
292

HOW TO ROLL YOUR OWN

294       Every calendar profile (holiday scheme) is a hash.
295
296       The name of the holiday (like "Christmas", for instance) serves as the
297       key in this hash and must therefore be unique (unless you want to over‐
298       ride a default which was set previously, but see below for more on
299       this).
300
301       The value for each key is either a string, which specifies a simple
302       date formula, or the reference of a callback function.
303
304       See the section "CALLBACK INTERFACE" above for a description of the
305       interface (in and out) of these callback functions.
306
307       See the section "DATE FORMULA SYNTAX" above and the description of the
308       "init()" method in Date::Calendar::Year(3) for the exact syntax of date
309       formula strings.
310
311       BEWARE that if keys are not unique in the source code, later entries
312       will overwrite previous ones! I.e.,
313
314           ...
315           "My special holiday" => "01-11",
316           "My special holiday" => "02-11",
317           ...
318
319       will NOT set two holidays of the same name, one on November first, the
320       other on November second, but only one, on November second!
321
322       Therefore, in order to use sets of defaults and to be able to override
323       some of them, you must FIRST include any hash containing the default
324       definitions, and THEN write down your own definitions (see also the
325       Date::Calendar::Profiles module for examples of this!), like this:
326
327           $defaults =
328           {
329               "Holiday #1" => "01-01",
330               "Holiday #2" => "02-02",
331               "Holiday #3" => "03-03"
332           };
333
334           $variant1 =
335           {
336               %$defaults,
337               "Holiday #2" => "09-02",
338               "Holiday #4" => "04-04"
339           };
340
341       This is because of the way hashes work in Perl.
342
343       Now let's suppose that you want to write a profile containing all your
344       relatives' and friends' birthdays or anniversaries.
345
346       Simply go ahead and list them in your program, in any order you like,
347       as follows (for example):
348
349         $Birthdays =
350         {
351             "Spouse 1971"             =>  "30.12.",
352             "Wedding Day 1992"        =>  "01.09.",
353             "Valentine's Day"         =>  "14.02.",
354             "Son Richard 1996"        =>  "11.05.",
355             "Daughter Irene 1994"     =>  "17.01.",
356             "Mom 1939"                =>  "19.08.",
357             "Dad 1937"                =>  "23.04.",
358             "Brother Timothy 1969"    =>  "24.04.",
359             "Sister Catherine 1973"   =>  "21.10.",
360             "Cousin Paul 1970"        =>  "16.10.",
361             "Aunt Marjorie 1944"      =>  "09.06.",
362             "Uncle George 1941"       =>  "02.08.",
363             "Friend Alexander 1968"   =>  "12.06.",
364         };
365
366       The year numbers after the names are not really necessary, but they
367       allow us to display the person's current age. If this year number is
368       omitted, we simply don't display the age.
369
370       Now in order to query this birthday database, we can use the following
371       little program:
372
373         #!perl -w
374
375         use strict;
376         no strict "vars";
377         use Date::Calc qw(:all);
378         use Date::Calendar;
379
380         $Birthdays =
381         {
382             ... # (see above)
383         };
384
385         @today = Today();
386         $calendar = Date::Calendar->new( $Birthdays );
387         $calendar->year( $today[0] );
388
389         foreach $key (@ARGV)
390         {
391             if (@list = $calendar->search( $key ))
392             {
393                 foreach $date (@list)
394                 {
395                     @labels = $calendar->labels( $date );
396                     $dow = shift(@labels);
397                     # More than one person might have birthday on the same date:
398                     $name = $key;
399                     foreach $person (@labels)
400                     {
401                         if (index(lc($person),lc($key)) >= 0)
402                         {
403                             $name = $person;
404                             last;
405                         }
406                     }
407                     $delta = Delta_Days(@today, $date->date());
408                     $age = '';
409                     if ($name =~ s!\s*(\d+)\s*$!!)
410                     {
411                         $age = $today[0] - $1;
412                         $age-- if ($delta > 0);
413                         $age = sprintf(" (%2d years old)", $age);
414                     }
415                     printf
416                     (
417                         "%-20.20s: %+5d days => %3.3s %2d-%3.3s-%4d%s\n",
418                         $name,
419                         $delta,
420                         $dow,
421                         $date->day(),
422                         Month_to_Text($date->month()),
423                         $date->year(),
424                         $age
425                     );
426                 }
427             }
428             else { print "No entry found in birthday list for '$key'!\n" }
429         }
430
431         __END__
432
433       Let us save this program as, say, "birthday.pl".
434
435       Then we can query this birthday database by providing search strings on
436       the command line, like this (note that this is a (case-insensitive)
437       substring search, NOT a regular expression match!):
438
439         > date
440         Wed Oct  3 18:05:45 CEST 2001
441
442         > perl birthday.pl wed spo
443         Wedding Day         :   -32 days => Sat  1-Sep-2001 ( 9 years old)
444         Spouse              :   +88 days => Sun 30-Dec-2001 (29 years old)
445
446         > perl birthday.pl son daug
447         Son Richard         :  -145 days => Fri 11-May-2001 ( 5 years old)
448         Daughter Irene      :  -259 days => Wed 17-Jan-2001 ( 7 years old)
449
450         > perl birthday.pl broth sist
451         Brother Timothy     :  -162 days => Tue 24-Apr-2001 (32 years old)
452         Sister Catherine    :   +18 days => Sun 21-Oct-2001 (27 years old)
453
454         > perl birthday.pl mom dad
455         Mom                 :   -45 days => Sun 19-Aug-2001 (62 years old)
456         Dad                 :  -163 days => Mon 23-Apr-2001 (64 years old)
457
458         > perl birthday.pl uncl aunt
459         Uncle George        :   -62 days => Thu  2-Aug-2001 (60 years old)
460         Aunt Marjorie       :  -116 days => Sat  9-Jun-2001 (57 years old)
461
462         > perl birthday.pl alex
463         Friend Alexander    :  -113 days => Tue 12-Jun-2001 (33 years old)
464
465       In order to get the whole list, we can supply a substring which is con‐
466       tained in every name, which happens to be a blank (" "):
467
468         > perl birthday.pl ' '
469         Daughter Irene      :  -259 days => Wed 17-Jan-2001 ( 7 years old)
470         Valentine's Day     :  -231 days => Wed 14-Feb-2001
471         Dad                 :  -163 days => Mon 23-Apr-2001 (64 years old)
472         Brother Timothy     :  -162 days => Tue 24-Apr-2001 (32 years old)
473         Son Richard         :  -145 days => Fri 11-May-2001 ( 5 years old)
474         Aunt Marjorie       :  -116 days => Sat  9-Jun-2001 (57 years old)
475         Friend Alexander    :  -113 days => Tue 12-Jun-2001 (33 years old)
476         Uncle George        :   -62 days => Thu  2-Aug-2001 (60 years old)
477         Mom                 :   -45 days => Sun 19-Aug-2001 (62 years old)
478         Wedding Day         :   -32 days => Sat  1-Sep-2001 ( 9 years old)
479         Cousin Paul         :   +13 days => Tue 16-Oct-2001 (30 years old)
480         Sister Catherine    :   +18 days => Sun 21-Oct-2001 (27 years old)
481         Spouse              :   +88 days => Sun 30-Dec-2001 (29 years old)
482
483       By the way, a similar program is included in the "examples" subdirec‐
484       tory of the Date::Calc distribution, called "anniversaries.pl".
485
486       See also the file "EXAMPLES.txt" in the distribution's main directory
487       for a short description of that little script.
488

SEE ALSO

490       Date::Calendar(3), Date::Calendar::Year(3), Date::Calc::Object(3),
491       Date::Calc(3).
492

KNOWN BUGS

494       The australian calendar profiles are known to contain wrong dates.
495       This is due to the fact that Australia decrees its holidays individu‐
496       ally for each year, difficulting the calculation of the holidays by way
497       of a formula. An effort to compare (and to correct) the current imple‐
498       mentation with official documents (web pages) by the Australian author‐
499       ities is under way. This hasn't been finished yet because it is very
500       time-consuming.
501

VERSION

503       This man page documents "Date::Calendar::Profiles" version 5.4.
504

AUTHOR

506         Steffen Beyer
507         mailto:sb@engelschall.com
508         http://www.engelschall.com/u/sb/download/
509
511       Copyright (c) 2000 - 2004 by Steffen Beyer. All rights reserved.
512

LICENSE

514       This package is free software; you can redistribute it and/or modify it
515       under the same terms as Perl itself, i.e., under the terms of the
516       "Artistic License" or the "GNU General Public License".
517
518       Please refer to the files "Artistic.txt" and "GNU_GPL.txt" in this dis‐
519       tribution for details!
520

DISCLAIMER

522       This package is distributed in the hope that it will be useful, but
523       WITHOUT ANY WARRANTY; without even the implied warranty of MER‐
524       CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
525
526       See the "GNU General Public License" for more details.
527
528
529
530perl v5.8.8                       2004-10-03       Date::Calendar::Profiles(3)
Impressum