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[,WEEKEND]] );
14         $cal_DE_BY = Date::Calendar->new( $Profiles->{'DE-BY'} [,LANG[,WEEKEND]] );
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[,WEEKEND]] );
22         $year_2001_DE_NW = Date::Calendar::Year->new( 2001, $Profiles->{'DE-NW'} [,LANG[,WEEKEND]] );
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
61       Date::Calendar::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
65       different formats, e.g. american or european), or things like "the
66       second Sunday of May" (Mother's Day), or "Easter Sunday minus 46 days"
67       (Ash 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
86       module Date::Calendar::Profiles exports the following utility
87       subroutines (which are meant to be used as "filters" in callback
88       functions of your own):
89
90       · "($year,$month,$day[,ANYTHING]) =
91         Previous_Friday($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]) =
103         Next_Monday($year,$month,$day[,ANYTHING]);"
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]) =
115         Next_Monday_or_Tuesday($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
138         Saturday 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]) =
165         Nearest_Workday($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]) =
179         Sunday_to_Monday($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
260       callback functions) if for instance you have a set of similar holidays
261       to calculate, like for instance the four Sundays before Christmas
262       ("Advent").
263
264       The callback function "Advent()" (exported by the
265       Date::Calendar::Profiles 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
279       commemorative date, i.e., that you don't get a day off from work on
280       that day.
281
282       The string ":" means that the date in question is a "half" holiday,
283       i.e., a day on which you get half a day off from work.
284
285       In case the holiday in question was not observed or did not exist in
286       the requested year, the callback function may also return an empty
287       list. This will cause the "init()" method to simply drop this holiday
288       for that year.
289
290       The module Date::Calendar::Profiles exports the sample callback
291       functions "Advent1()", "Advent2()", "Advent3()", "Advent4()" and
292       "Advent()", which might assist you in rolling your own profiles.
293

HOW TO ROLL YOUR OWN

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

SEE ALSO

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

LIMITATIONS

495       The calendar profiles included in this module usually do not take
496       historical irregularities into account (even though some do in order to
497       show how this can be done), they only provide means for calculating
498       regularly recurring events (the profiles should therefore not be relied
499       upon for historical faithfulness).
500

KNOWN BUGS

502       The australian calendar profiles are known to contain wrong dates.
503       This is due to the fact that Australia decrees its holidays
504       individually for each year, difficulting the calculation of the
505       holidays by way of a formula. An effort to compare (and to correct) the
506       current implementation with official documents (web pages) by the
507       Australian authorities is under way. This hasn't been finished yet
508       because it is very time-consuming.
509

VERSION

511       This man page documents "Date::Calendar::Profiles" version 6.3.
512

AUTHOR

514         Steffen Beyer
515         mailto:STBEY@cpan.org
516         http://www.engelschall.com/u/sb/download/
517
519       Copyright (c) 2000 - 2009 by Steffen Beyer. All rights reserved.
520

LICENSE

522       This package is free software; you can use, modify and redistribute it
523       under the same terms as Perl itself, i.e., at your option, under the
524       terms either of the "Artistic License" or the "GNU General Public
525       License".
526
527       The C library at the core of the module "Date::Calc::XS" can, at your
528       discretion, also be used, modified and redistributed under the terms of
529       the "GNU Library General Public License".
530
531       Please refer to the files "Artistic.txt", "GNU_GPL.txt" and
532       "GNU_LGPL.txt" in the "license" subdirectory of this distribution for
533       any details!
534

DISCLAIMER

536       This package is distributed in the hope that it will be useful, but
537       WITHOUT ANY WARRANTY; without even the implied warranty of
538       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
539
540       See the "GNU General Public License" for more details.
541
542
543
544perl v5.10.1                      2009-10-31       Date::Calendar::Profiles(3)
Impressum