Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Date::Calendar::Year.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "YEAR 1"
132.TH YEAR 1 "2002-09-28" "perl v5.8.0" "User Contributed Perl Documentation"
133.SH "NAME"
134Date::Calendar::Year \- Implements embedded "year" objects for Date::Calendar
135.SH "MOTTO"
136.IX Header "MOTTO"
137There is more than one way to do it \- this is just one of them!
138.SH "PREFACE"
139.IX Header "PREFACE"
140Note that Date::Calendar::Year (and Date::Calendar) can only deal
141with years lying within the range [1583..2299].
142.SH "SYNOPSIS"
143.IX Header "SYNOPSIS"
144.Vb 2
145\& use Date::Calendar::Year qw( check_year empty_period );
146\& use Date::Calendar::Year qw( :all ); # same as above
147.Ve
148.PP
149.Vb 2
150\& check_year(YEAR|DATE); # dies if year < 1583 or year > 2299
151\& empty_period(); # warns about empty interval if $^W is set
152.Ve
153.PP
154.Vb 2
155\& $index = $year->date2index(YEAR,MONTH,DAY|DATE);
156\& $date = $year->index2date(INDEX);
157.Ve
158.PP
159.Vb 3
160\& use Date::Calendar::Profiles qw( $Profiles );
161\& $year_2000_US_FL = Date::Calendar::Year->new( 2000, $Profiles->{'US-FL'} [,LANG] );
162\& $year_2001_DE_NW = Date::Calendar::Year->new( 2001, $Profiles->{'DE-NW'} [,LANG] );
163.Ve
164.PP
165.Vb 2
166\& $year = Date::Calendar::Year->new( 2001, {} );
167\& $year->init( 2002, $Profiles->{'DE-SN'} [,LANG] );
168.Ve
169.PP
170.Vb 7
171\& $vector = $year->vec_full(); # vector of full holidays
172\& $vector = $year->vec_half(); # vector of half holidays
173\& $vector = $year->vec_work(); # NOT a vector of workdays but a workspace!
174\& $size = $year->val_days(); # number of days in that year, size of vectors
175\& $base = $year->val_base(); # number of days for [year,1,1] since [1,1,1]
176\& $number = $year->val_year(); # the year's number itself
177\& $number = $year->year(); # alias for val_year()
178.Ve
179.PP
180.Vb 3
181\& @names = $year->labels(YEAR,MONTH,DAY|DATE);
182\& @holidays = $year->labels();
183\& $holidays = $year->labels();
184.Ve
185.PP
186.Vb 2
187\& @dates = $year->search(PATTERN);
188\& $dates = $year->search(PATTERN);
189.Ve
190.PP
191.Vb 3
192\& $days = $year->delta_workdays(YEAR,MONTH1,DAY1|DATE1
193\& ,YEAR,MONTH2,DAY2|DATE2
194\& ,FLAG1,FLAG2);
195.Ve
196.PP
197.Vb 2
198\& ($date,$rest,$sign) = $year->add_delta_workdays(YEAR,MONTH,DAY|DATE
199\& ,DELTA,SIGN);
200.Ve
201.PP
202.Vb 3
203\& $flag = $year->is_full(YEAR,MONTH,DAY|DATE);
204\& $flag = $year->is_half(YEAR,MONTH,DAY|DATE);
205\& $flag = $year->is_work(YEAR,MONTH,DAY|DATE);
206.Ve
207.SH "INTERFACE"
208.IX Header "INTERFACE"
209Note that whenever a year number, a date, a time or a combined
210date and time are expected as input parameters by one of the
211methods of this class, you can always pass a Date::Calc[::Object]
212date object or an array reference (of an array of appropriate
213length) instead!
214.PP
215See \fIDate::Calc::Object\fR\|(3) for more details.
216.PP
217So instead of calling a given method like this:
218.PP
219.Vb 3
220\& $object->method1( $year,$month,$day );
221\& $object->method2( $year1,$month1,$day1, $year2,$month2,$day2 );
222\& $object->method3( $year1, $year2, $year3 );
223.Ve
224.PP
225You can also call it like so:
226.PP
227.Vb 2
228\& $object->method1( $date );
229\& $object->method1( [1964,1,3] );
230.Ve
231.PP
232.Vb 8
233\& $object->method2( $year1,$month1,$day1, $date2 );
234\& $object->method2( $date1, $year2,$month2,$day2 );
235\& $object->method2( $date1, $date2 );
236\& $object->method2( $year1,$month1,$day1, [2001,3,17] );
237\& $object->method2( [1964,1,3], $year2,$month2,$day2 );
238\& $object->method2( [1964,1,3], [2001,3,17] );
239\& $object->method2( $date1, [2001,3,17] );
240\& $object->method2( [1964,1,3], $date2 );
241.Ve
242.PP
243.Vb 1
244\& $object->method3( $year1, $date2, [2001,3,17] );
245.Ve
246.PP
247And similarly if a time or a combined date and time are expected.
248.PP
249If you substitute an expected year number by an anonymous array
250(this is the recommended way of writing date constants, for
251increased readability of your programs), it must contain three
252values, nevertheless (otherwise the use of an anonymous array
253would be pointless).
254.PP
255Don't confuse year numbers and their substitutes (a date object
256or an array reference) with Date::Calendar::Year objects, which
257are a totally different thing!
258.PP
259But incidentally \f(CW\*(C`:\-)\*(C'\fR, you may also pass a Date::Calendar::Year
260object whenever a year number is expected. However, and perhaps
261against your expectations at times, only the year number from
262that object will be used, not the year object itself (the year
263object in question might be using the wrong profile!).
264.PP
265Moreover, whenever a method of this class returns a date, it
266does so by returning a Date::Calc[::Object] date object.
267.SH "IMPLEMENTATION"
268.IX Header "IMPLEMENTATION"
269Each Date::Calendar::Year object consists mainly of three bit
270vectors, plus some administrative attributes, all stored in a
271(blessed) hash.
272.PP
273All three bit vectors contain as many bits as there are days
274in the corresponding year, i.e., either 365 or 366.
275.PP
276The first bit vector, called \*(L"\s-1FULL\s0\*(R", contains set bits for
277Saturdays, Sundays and all \*(L"full\*(R" legal holidays (i.e.,
278days off, on which you usually do not work).
279.PP
280The second bit vector, called \*(L"\s-1HALF\s0\*(R", contains set bits for
281all \*(L"half\*(R" holidays, i.e., holidays where you get only half
282a day off from work.
283.PP
284The third and last bit vector, called \*(L"\s-1WORK\s0\*(R", is used as a
285workspace, in which various calculations are performed
286throughout this module.
287.PP
288Its name does \fB\s-1NOT\s0\fR come from \*(L"working days\*(R" (as you might
289think), but from \*(L"workspace\*(R".
290.PP
291It only so happens that it is used to calculate the working
292days sometimes, at some places in this module.
293.PP
294But you are free to use it yourself, for whatever calculation
295you would like to carry out yourself.
296.PP
297The two other bit vectors, \*(L"\s-1FULL\s0\*(R" and \*(L"\s-1HALF\s0\*(R", should never be
298changed, unless you know \fB\s-1EXACTLY\s0\fR what you're doing!
299.SH "DESCRIPTION"
300.IX Header "DESCRIPTION"
301Functions
302.IP "\(bu" 2
303\&\f(CW\*(C`check_year(YEAR);\*(C'\fR
304.Sp
305This function checks that the given year lies in the permitted
306range [1583..2299]. It returns nothing in case of success, and
307throws an exception (\*(L"given year out of range [1583..2299]\*(R")
308otherwise.
309.IP "\(bu" 2
310\&\f(CW\*(C`empty_period();\*(C'\fR
311.Sp
312This function issues a warning (from the perspective of the
313caller of a Date::* module) that the given range of dates is
314empty (\*(L"dates interval is empty\*(R"), provided that warnings are
315enabled (i.e., "\f(CW$^W\fR" is true).
316.Sp
317This function is currently used by the method \*(L"\fIdelta_workdays()\fR\*(R"
318in this class, and by its equivalent from the Date::Calendar
319module.
320.Sp
321It is called whenever the range of dates of which the difference
322in working days is to be calculated is empty. This can happen for
323instance if you specify two adjacent dates both of which are not
324to be included in the difference.
325.PP
326Methods
327.IP "\(bu" 2
328\&\f(CW\*(C`$index = $year\->date2index(YEAR,MONTH,DAY|DATE);\*(C'\fR
329.Sp
330This method converts a given date into the number of the day in
331that year (this is sometimes also referred to as the \*(L"julian\*(R"
332date), i.e., a number between 0 (for January 1st) and the number
333of days in the given year minus one, i.e., 364 or 365 (for
334December 31st).
335.Sp
336You may need this in order to access the bit vectors returned
337by the methods \*(L"\fIvec_full()\fR\*(R", \*(L"\fIvec_half()\fR\*(R" and \*(L"\fIvec_work()\fR\*(R".
338.Sp
339Note that there are shorthand methods in this module called
340\&\*(L"\fIis_full()\fR\*(R", \*(L"\fIis_half()\fR\*(R" and \*(L"\fIis_work()\fR\*(R", which serve to test
341individual bits of the three bit vectors which are a part of
342each Date::Calendar::Year object.
343.Sp
344An exception (\*(L"given year != object's year\*(R") is thrown if the
345year associated with the year object itself and the year from
346the given date do not match.
347.Sp
348An exception (\*(L"invalid date\*(R") is also thrown if the given
349arguments do not constitute a valid date, or (\*(L"given year
350out of range [1583..2299]\*(R") if the given year lies outside
351of the permitted range.
352.IP "\(bu" 2
353\&\f(CW\*(C`$date = $year\->index2date(INDEX);\*(C'\fR
354.Sp
355This method converts an index (or \*(L"julian date\*(R") for the
356given year back into a date.
357.Sp
358An exception (\*(L"invalid index\*(R") is thrown if the given index
359is outside of the permitted range for the given year, i.e.,
360\&\f(CW\*(C`[0..364]\*(C'\fR or \f(CW\*(C`[0..365]\*(C'\fR.
361.Sp
362Note that this method returns a Date::Calc \fB\s-1OBJECT\s0\fR!
363.IP "\(bu" 2
364\&\f(CW\*(C`$year_2000_US_FL = Date::Calendar::Year\->new( 2000, $Profiles\->{'US\-FL'} [,LANG] );\*(C'\fR
365.Sp
366\&\f(CW\*(C`$year_2001_DE_NW = Date::Calendar::Year\->new( 2001, $Profiles\->{'DE\-NW'} [,LANG] );\*(C'\fR
367.Sp
368\&\f(CW\*(C`$year = Date::Calendar::Year\->new( 2001, {} );\*(C'\fR
369.Sp
370This is the constructor method. Call it to create a new
371Date::Calendar::Year object.
372.Sp
373The first argument must be a year number in the range
374[1583..2299].
375.Sp
376The second argument must be the reference of a hash,
377which usually contains names of holidays and commemorative
378days as keys and strings containing the date or formula
379for each holiday as values.
380.Sp
381Reading this hash and initializing the object's internal
382data is performed by an extra method, called \*(L"\fIinit()\fR\*(R",
383which is called internally by the constructor method,
384and which is described immediately below, after this
385method.
386.Sp
387In case you call the \*(L"\fIinit()\fR\*(R" method yourself, explicitly,
388after creating the object, you can pass an empty profile
389(e.g., just an empty anonymous hash) to the \*(L"\fInew()\fR\*(R" method
390in order to improve performance.
391.Sp
392The third argument is optional, and must consist of
393the valid name or number of a language as provided by
394the \fIDate::Calc\fR\|(3) module if given.
395.Sp
396This argument determines which language shall be used
397when reading the profile, since the profile may contain
398names of months and weekdays in its formulas in that
399language.
400.Sp
401The default is English if none is specified.
402.IP "\(bu" 2
403\&\f(CW\*(C`$year\->init( 2002, $Profiles\->{'DE\-SN'} [,LANG] );\*(C'\fR
404.Sp
405This method is called by the \*(L"\fInew()\fR\*(R" constructor method,
406internally, and has the same arguments as the latter.
407.Sp
408See immediately above for a description of these arguments.
409.Sp
410Note that you can also call this method explicitly yourself,
411if needed, and you can of course subclass the Date::Calendar::Year
412class and override the \*(L"\fIinit()\fR\*(R" method with an method of your own.
413.Sp
414The holiday scheme or \*(L"profile\*(R" (i.e., the reference of
415a hash passed as the second argument to this method) must
416obey the following semantics and syntax:
417.Sp
418The keys are the names of the holiday or commemorative day
419in question. Keys must be unique (but see further below).
420.Sp
421The difference between a holiday and a commemorative day is
422that you (usually) get a day off on a holiday, whereas on a
423purely commemorative day, you don't.
424.Sp
425A commemorative day is just a date with a name, nothing more.
426.Sp
427The values belonging to these keys can either be the code
428reference of a callback function (see \fIDate::Calendar::Profiles\fR\|(3)
429for more details and examples), or a string.
430.Sp
431All other values cause a fatal error with program abortion.
432.Sp
433The strings can specify three types of dates:
434.Sp
435.Vb 2
436\& - fixed dates
437\& (like New Year, or first of January),
438.Ve
439.Sp
440.Vb 2
441\& - dates relative to Easter Sunday
442\& (like Ascension = Easter Sunday + 39 days), and
443.Ve
444.Sp
445.Vb 3
446\& - the 1st, 2nd, 3rd, 4th or last
447\& of a given day of week in a given month
448\& (like "the 4th Thursday of November", or Thanksgiving).
449.Ve
450.Sp
451All other types of dates must be specified via callback
452functions.
453.Sp
454Note that the \*(L"last\*(R" of a given day of week is written as
455the \*(L"5th\*(R", because the last is always either the 5th or the
4564th of the given day of week. So the \*(L"\fIinit()\fR\*(R" module first
457calculates the 5th of the requested day of week, and if that
458doesn't exist, takes the 4th instead.
459.Sp
460There are also two modifier characters which may prefix the
461string with the date formula, \*(L"#\*(R" and \*(L":\*(R".
462.Sp
463The character \*(L"#\*(R" (mnemonic: it's only a comment) signals
464that the date in question is a purely commemorative day,
465i.e., it will not enter into any date calculations, but
466can be queried with the \*(L"\fIlabels()\fR\*(R" and \*(L"\fIsearch()\fR\*(R" methods,
467and appears when printing a calendar, for instance.
468.Sp
469The character \*(L":\*(R" (mnemonic: divided into two halfs) specifies
470that the date in question is only a \*(L"half\*(R" holiday, i.e., you
471only get half a day off instead of a full day. Some companies
472have this sort of thing. \f(CW\*(C`:\-)\*(C'\fR
473.Sp
474The exact syntax for the date formula strings is the following
475(by example):
476.Sp
477.Vb 1
478\& - Fixed dates:
479.Ve
480.Sp
481.Vb 2
482\& "Christmas" => "24.12", # European format (day, month)
483\& "Christmas" => "24.12.",
484.Ve
485.Sp
486.Vb 4
487\& "Christmas" => "24Dec",
488\& "Christmas" => "24.Dec",
489\& "Christmas" => "24Dec.",
490\& "Christmas" => "24.Dec.",
491.Ve
492.Sp
493.Vb 2
494\& "Christmas" => "24-12",
495\& "Christmas" => "24-12-",
496.Ve
497.Sp
498.Vb 2
499\& "Christmas" => "24-Dec",
500\& "Christmas" => "24-Dec-",
501.Ve
502.Sp
503.Vb 3
504\& "Christmas" => "12/25", # American format (month, day)
505\& "Christmas" => "Dec25",
506\& "Christmas" => "Dec/25",
507.Ve
508.Sp
509.Vb 1
510\& - Dates relative to Easter Sunday:
511.Ve
512.Sp
513.Vb 13
514\& "Ladies' Carnival" => "-52",
515\& "Carnival Monday" => "-48",
516\& "Mardi Gras" => "-47",
517\& "Ash Wednesday" => "-46",
518\& "Palm Sunday" => "-7",
519\& "Maundy Thursday" => "-3",
520\& "Good Friday" => "-2",
521\& "Easter Sunday" => "+0",
522\& "Easter Monday" => "+1",
523\& "Ascension" => "+39",
524\& "Whitsunday" => "+49",
525\& "Whitmonday" => "+50",
526\& "Corpus Christi" => "+60",
527.Ve
528.Sp
529.Vb 1
530\& - The 1st, 2nd, 3rd, 4th or last day of week:
531.Ve
532.Sp
533.Vb 7
534\& "Thanksgiving" => "4Thu11",
535\& "Thanksgiving" => "4/Thu/Nov",
536\& "Columbus Day" => "2/Mon/Oct",
537\& "Columbus Day" => "2/Mon/10",
538\& "Columbus Day" => "2/1/Oct",
539\& "Columbus Day" => "2/1/10",
540\& "Memorial Day" => "5/Mon/May", # LAST Monday of May
541.Ve
542.Sp
543Remember that each of these date formula strings may
544also be prefixed with either \*(L"#\*(R" or \*(L":\*(R":
545.Sp
546.Vb 2
547\& "Christmas" => ":24.12.", # only half a day off
548\& "Valentine's Day" => "#Feb/14", # not an official holiday
549.Ve
550.Sp
551Note that the name of the month or day of week may have any
552length you like, it just must specify the intended month or
553day of week unambiguously. So \*(L"D\*(R", \*(L"De\*(R", \*(L"Dec\*(R", \*(L"Dece\*(R",
554\&\*(L"Decem\*(R", \*(L"Decemb\*(R", \*(L"Decembe\*(R" and \*(L"December\*(R" would all
555be valid, for example. Note also that case is ignored.
556.Sp
557When specifying day and month numbers, or offsets relative
558to Easter Sunday, leading zeros are permitted (for nicely
559indented formatting, for instance) but ignored.
560.Sp
561Leading zeros are not permitted in front of the ordinal
562number [1..5] or the number of the day of week [1..7]
563when specifying the nth day of week in a month.
564.Sp
565\&\fB\s-1BEWARE\s0\fR that if keys are not unique in the source code,
566later entries will overwrite previous ones! I.e.,
567.Sp
568.Vb 4
569\& ...
570\& "My special holiday" => "01-11",
571\& "My special holiday" => "02-11",
572\& ...
573.Ve
574.Sp
575will \fB\s-1NOT\s0\fR set two holidays of the same name, one on November
576first, the other on November second, but only one, on November
577second!
578.Sp
579Therefore, in order to use sets of defaults and to be able
580to override some of them, you must \fB\s-1FIRST\s0\fR include any hash
581containing the default definitions, and \fB\s-1THEN\s0\fR write down
582your own definitions (see also the Date::Calendar::Profiles
583module for examples of this!), like this:
584.Sp
585.Vb 6
586\& $defaults =
587\& {
588\& "Holiday #1" => "01-01",
589\& "Holiday #2" => "02-02",
590\& "Holiday #3" => "03-03"
591\& };
592.Ve
593.Sp
594.Vb 6
595\& $variant1 =
596\& {
597\& %$defaults,
598\& "Holiday #2" => "09-02",
599\& "Holiday #4" => "04-04"
600\& };
601.Ve
602.Sp
603This is because of the way hashes work in Perl.
604.Sp
605The \*(L"\fIinit()\fR\*(R" method proceeds as follows:
606.Sp
607First it checks whether the given year number lies in
608the range [1583..2299]. A fatal error occurs if not.
609.Sp
610Then it determines the number of days in the requested
611year, and stores it in the given Date::Calendar::Year
612object.
613.Sp
614It then calls the \fIBit::Vector\fR\|(3) module to allocate three
615bit vectors with a number of bits equal to the number of
616days in the requested year, and stores the three object
617references (of the bit vectors) in the Date::Calendar::Year
618object.
619.Sp
620(See also the description of the three methods \*(L"\fIvec_full()\fR\*(R",
621\&\*(L"\fIvec_half()\fR\*(R" and \*(L"\fIvec_full()\fR\*(R" immediately below.)
622.Sp
623It then sets the bits which correspond to Saturdays and
624Sundays in the \*(L"full holidays\*(R" bit vector.
625.Sp
626At last, it iterates over the keys of the given holiday
627scheme (of the hash referred to by the hash reference
628passed to the \*(L"\fIinit()\fR\*(R" method as the second argument),
629evaluates the formula (or calls the given callback
630function), and sets the corresponding bit in the \*(L"full\*(R"
631or \*(L"half\*(R" holidays bit vector if the calculated date
632is valid.
633.Sp
634A fatal error occurs if the date formula cannot be parsed
635or if the date returned by a formula or callback function
636is invalid (e.g. 30\-Feb\-2001 or the like) or lies outside
637the given year (e.g. Easter+365).
638.Sp
639Finally, the \*(L"\fIinit()\fR\*(R" method makes sure that days marked
640as \*(L"full\*(R" holidays do not appear as \*(L"half\*(R" holidays as
641well.
642.Sp
643Then the \*(L"\fIinit()\fR\*(R" method returns.
644.Sp
645Note that when deciphering the date formulas, the \*(L"\fIinit()\fR\*(R"
646method uses the functions \*(L"\fIDecode_Day_of_Week()\fR\*(R" and
647\&\*(L"\fIDecode_Month()\fR\*(R" from the \fIDate::Calc\fR\|(3) module, which
648are language\-dependent.
649.Sp
650Therefore the \*(L"\fIinit()\fR\*(R" method allows you to pass it an optional
651third argument, which must consist of the valid name or number
652of a language as provided by the \fIDate::Calc\fR\|(3) module.
653.Sp
654For the time of scanning the given holiday scheme, the \*(L"\fIinit()\fR\*(R"
655method will temporarily set the language to the value specified,
656and it will restore the original value before returning.
657.Sp
658The default is English if none is specified.
659.Sp
660This means that you can provide the names of months and days of
661week in your holiday profile in any of the languages supported
662by the \fIDate::Calc\fR\|(3) module, provided you give the \*(L"\fIinit()\fR\*(R"
663method a clue (the third parameter) which language to expect.
664.IP "\(bu" 2
665\&\f(CW\*(C`$vector = $year\->vec_full();\*(C'\fR
666.Sp
667This method returns a reference to the bit vector in the
668given year object which contains all \*(L"full\*(R" holidays.
669.Sp
670\&\fB\s-1BEWARE\s0\fR that you should \fB\s-1NEVER\s0\fR change the contents of this
671bit vector unless you know \fB\s-1EXACTLY\s0\fR what you're doing!
672.Sp
673You should usually only read from this bit vector, or use it
674as an operand in bit vector operations \- but never as an
675lvalue.
676.IP "\(bu" 2
677\&\f(CW\*(C`$vector = $year\->vec_half();\*(C'\fR
678.Sp
679This method returns a reference to the bit vector in the
680given year object which contains all \*(L"half\*(R" holidays.
681.Sp
682\&\fB\s-1BEWARE\s0\fR that you should \fB\s-1NEVER\s0\fR change the contents of this
683bit vector unless you know \fB\s-1EXACTLY\s0\fR what you're doing!
684.Sp
685You should usually only read from this bit vector, or use it
686as an operand in bit vector operations \- but never as an
687lvalue.
688.IP "\(bu" 2
689\&\f(CW\*(C`$vector = $year\->vec_work();\*(C'\fR
690.Sp
691This method returns a reference to the \*(L"workspace\*(R" bit vector
692in the given year object.
693.Sp
694Note that you cannot rely on the contents of this bit vector.
695.Sp
696You have to set it up yourself before performing any calculations
697with it.
698.Sp
699Currently the contents of this bit vector are modified by the
700two methods \*(L"\fIdelta_workdays()\fR\*(R" and \*(L"\fIadd_delta_workdays()\fR\*(R", in
701ways which are hard to predict.
702.Sp
703The size of this bit vector can be determined through either
704"\f(CW\*(C`$days = $vector\->Size();\*(C'\fR\*(L" or
705\&\*(R"\f(CW\*(C`$days = $year\->val_days();\*(C'\fR".
706.IP "\(bu" 2
707\&\f(CW\*(C`$size = $year\->val_days();\*(C'\fR
708.Sp
709This method returns the number of days in the given year object,
710i.e., either 365 or 366. This is also the size (number of bits)
711of the three bit vectors contained in the given year object.
712.IP "\(bu" 2
713\&\f(CW\*(C`$base = $year\->val_base();\*(C'\fR
714.Sp
715This method returns the value of the expression
716"\f(CW\*(C`Date_to_Days($year\->val_year(),1,1)\*(C'\fR", or in other words,
717the number of days between January 1st of the year 1 and January
7181st of the given year, plus one.
719.Sp
720This value is used internally by the method \*(L"\fIdate2index()\fR\*(R" in order
721to calculate the \*(L"julian\*(R" date or day of the year for a given date.
722.Sp
723The expression above is computed only once in method \*(L"\fIinit()\fR\*(R" and
724then stored in one of the year object's attributes, of which this
725method just returns the value.
726.IP "\(bu" 2
727\&\f(CW\*(C`$number = $year\->val_year();\*(C'\fR
728.Sp
729\&\f(CW\*(C`$number = $year\->year();\*(C'\fR
730.Sp
731These two methods are identical, the latter being a shortcut of
732the former.
733.Sp
734They return the number of the year for which a calendar has been
735stored in the given year object.
736.Sp
737The method name \*(L"\fIval_year()\fR\*(R" is used here in order to be consistent
738with the other attribute accessor methods of this class, and the
739method \*(L"\fIyear()\fR\*(R" is necessary in order to be able to pass
740Date::Calendar::Year objects as parameters instead of a year number
741in the methods of the Date::Calendar and Date::Calendar::Year
742modules.
743.IP "\(bu" 2
744\&\f(CW\*(C`@names = $year\->labels(YEAR,MONTH,DAY|DATE);\*(C'\fR
745.Sp
746\&\f(CW\*(C`@holidays = $year\->labels();\*(C'\fR
747.Sp
748\&\f(CW\*(C`$holidays = $year\->labels();\*(C'\fR
749.Sp
750If any arguments are given, they are supposed to represent a
751date. In that case, a list of all labels (= names of holidays)
752associated with that date are returned. The first item returned
753is always the name of the day of week for that date.
754.Sp
755If no arguments are given, the list of all available labels in
756the given year is returned. This list does \fB\s-1NOT\s0\fR include any
757names of the days of week (which would be pointless in this case).
758.Sp
759In list context, the resulting list itself is returned. In scalar
760context, the number of items in the resulting list is returned.
761.IP "\(bu" 2
762\&\f(CW\*(C`@dates = $year\->search(PATTERN);\*(C'\fR
763.Sp
764\&\f(CW\*(C`$dates = $year\->search(PATTERN);\*(C'\fR
765.Sp
766This method searches through all the labels of the given year
767and returns a list of date objects with all dates whose labels
768match the given pattern.
769.Sp
770Note that this is a simple, case-insensitive substring search,
771\&\fB\s-1NOT\s0\fR a full-fledged regular expression search!
772.Sp
773The result is guaranteed to be sorted chronologically.
774.Sp
775In scalar context, only the number of items in the resulting list
776is returned, instead of the resulting list itself (as in list context).
777.IP "\(bu" 2
778\&\f(CW\*(C`$days = $year\->delta_workdays(YEAR,MONTH1,DAY1, YEAR,MONTH2,DAY2, FLAG1,FLAG2);\*(C'\fR
779.Sp
780\&\f(CW\*(C`$days = $year\->delta_workdays(DATE1,DATE2,FLAG1,FLAG2);\*(C'\fR
781.Sp
782This method calculates the number of work days (i.e., the number
783of days, but excluding all holidays) between two dates.
784.Sp
785In other words, this method is equivalent to the \*(L"\fIDelta_Days()\fR\*(R"
786function of the Date::Calc module, except that it disregards
787holidays in its counting.
788.Sp
789The two flags indicate whether the start and end dates should be
790included in the counting (that is, of course, only in case they
791aren't holidays), or not.
792.Sp
793It is common, for example, that you want to know how many work
794days are left between the current date and a given deadline.
795.Sp
796Typically, you will want to count the current date but not the
797deadline's date. So you would specify \*(L"true\*(R" (\*(L"1\*(R") for \s-1FLAG1\s0
798and \*(L"false\*(R" (\*(L"0\*(R") for \s-1FLAG2\s0 in order to achieve that.
799.Sp
800In other words, a value of \*(L"true\*(R" means \*(L"including this date\*(R",
801a value of \*(L"false\*(R" means \*(L"excluding this date\*(R".
802.Sp
803As with the \*(L"\fIDelta_Days()\fR\*(R" function from the Date::Calc module,
804the dates have to be given in chronological order to yield a
805positive result. If the dates are reversed, the result will
806be negative.
807.Sp
808The parameter \s-1FLAG1\s0 is associated with the first given date,
809the parameter \s-1FLAG2\s0 with the second given date (regardless
810of whether the dates are in chronological order or not).
811.Sp
812An exception (\*(L"given year != object's year\*(R") is thrown if the
813year number of either of the two given dates does not match the
814year number associated with the given year object.
815.Sp
816An exception (\*(L"invalid date\*(R") is also raised if either of the
817two date arguments does not constitute a valid date.
818.IP "\(bu" 2
819\&\f(CW\*(C`($date,$rest,$sign) = $year\->add_delta_workdays(YEAR,MONTH,DAY, DELTA, SIGN);\*(C'\fR
820.Sp
821\&\f(CW\*(C`($date,$rest,$sign) = $year\->add_delta_workdays(DATE,DELTA,SIGN);\*(C'\fR
822.Sp
823This method is the equivalent of the \*(L"\fIAdd_Delta_Days()\fR\*(R" function
824from the Date::Calc module, except that it adds work days and
825skips holidays.
826.Sp
827In other words, you can add or subtract a number of work days
828\&\*(L"\s-1DELTA\s0\*(R" to/from a given date and get a new date as the result
829(as a Date::Calc object).
830.Sp
831You add days (i.e., you go forward in time) with a positive
832offset \*(L"\s-1DELTA\s0\*(R", and you subtract days (i.e., you go backwards
833in time) with a negative offset.
834.Sp
835Note that an exception (\*(L"invalid date\*(R") is raised if the
836given date argument (the \*(L"start\*(R" date) does not constitute
837a valid date.
838.Sp
839Beware that this method is limited to date calculations within
840a single year (in contrast to the method with the same name
841from the Date::Calendar module).
842.Sp
843Therefore, the method does not only return a date (object),
844but also a \*(L"rest\*(R" and a \*(L"sign\*(R".
845.Sp
846The \*(L"rest\*(R" indicates how many days are still left from your
847original \s-1DELTA\s0 after going in the desired direction and
848reaching a year boundary.
849.Sp
850The \*(L"sign\*(R" indicates in which direction (future or past) one
851needs to go in order to \*(L"eat up\*(R" the \*(L"rest\*(R" (by subtracting
852a day from the \*(L"rest\*(R" for each work day passed), or to adjust
853the resulting date (in order to skip any holidays directly
854after a year boundary), if at all.
855.Sp
856The \*(L"sign\*(R" is \-1 for going backwards in time, +1 for going
857forward, and 0 if the result doesn't need any more fixing
858(for instance because the result lies in the same year as
859the starting date).
860.Sp
861The method \*(L"\fIadd_delta_workdays()\fR\*(R" from the Date::Calendar
862module uses the \*(L"rest\*(R" and \*(L"sign\*(R" return values from this
863method in order to perform calculations which may cross
864year boundaries.
865.Sp
866Therefore, it is not recommended to use this method here
867directly, as it is rather clumsy to use, but to use the
868method with the same name from the Date::Calendar module
869instead, which does the same but is much easier to use
870and moreover allows calculations which cross an arbitrary
871number of year boundaries.
872.IP "\(bu" 2
873\&\f(CW\*(C`$flag = $year\->is_full(YEAR,MONTH,DAY|DATE);\*(C'\fR
874.Sp
875This method returns \*(L"true\*(R" (\*(L"1\*(R") if the bit corresponding to
876the given date is set in the bit vector representing \*(L"full\*(R"
877holidays, and \*(L"false\*(R" (\*(L"0\*(R") otherwise.
878.Sp
879I.e., the method returns \*(L"true\*(R" if the given date is a (full)
880holiday (according to the calendar profile associated with the
881given year object).
882.IP "\(bu" 2
883\&\f(CW\*(C`$flag = $year\->is_half(YEAR,MONTH,DAY|DATE);\*(C'\fR
884.Sp
885This method returns \*(L"true\*(R" (\*(L"1\*(R") if the bit corresponding to
886the given date is set in the bit vector representing \*(L"half\*(R"
887holidays, and \*(L"false\*(R" (\*(L"0\*(R") otherwise.
888.Sp
889I.e., the method returns \*(L"true\*(R" if the given date is a half
890holiday (according to the calendar profile associated with the
891given year object).
892.Sp
893Note that if a date is a \*(L"full\*(R" holiday, the \*(L"half\*(R" bit is
894never set, even if you try to do so in your calendar profile,
895on purpose or by accident.
896.IP "\(bu" 2
897\&\f(CW\*(C`$flag = $year\->is_work(YEAR,MONTH,DAY|DATE);\*(C'\fR
898.Sp
899This method returns \*(L"true\*(R" (\*(L"1\*(R") if the bit corresponding to
900the given date is set in the bit vector used to perform all
901sorts of calculations, and \*(L"false\*(R" (\*(L"0\*(R") otherwise.
902.Sp
903\&\fB\s-1BEWARE\s0\fR that the \*(L"work\*(R" in this method's name does \fB\s-1NOT\s0\fR
904come from \*(L"work days\*(R"!
905.Sp
906It comes from the fact that the corresponding bit vector can
907be used for any \*(L"work\*(R" that you need to do. In other words,
908it's a \*(L"work space\*(R".
909.Sp
910Therefore, this bit vector might contain about everything you
911could imagine \- including a bit pattern which marks all \*(L"work
912days\*(R" with set bits, if it so happens!
913.Sp
914But you better don't rely on it, unless you put the bit pattern
915there yourself in the first place.
916.Sp
917Note that you can get a reference to this bit vector (in order
918to fill it with any bit pattern you like) using the method
919\&\*(L"\fIvec_work()\fR\*(R", described further above in this document.
920.Sp
921The number of bits in this bit vector is the same as the number
922of days in the given year "\f(CW$year\fR\*(L", which you can retrieve
923through either \*(R"\f(CW\*(C`$days = $year\->vec_work\->Size();\*(C'\fR\*(L"
924or \*(R"\f(CW\*(C`$days = $year\->val_days();\*(C'\fR".
925.Sp
926See also \fIBit::Vector\fR\|(3) for more details.
927.SH "SEE ALSO"
928.IX Header "SEE ALSO"
929\&\fIBit::Vector\fR\|(3), \fIDate::Calendar\fR\|(3), \fIDate::Calendar::Profiles\fR\|(3),
930\&\fIDate::Calc::Object\fR\|(3), \fIDate::Calc\fR\|(3).
931.SH "VERSION"
932.IX Header "VERSION"
933This man page documents \*(L"Date::Calendar::Year\*(R" version 5.3.
934.SH "AUTHOR"
935.IX Header "AUTHOR"
936.Vb 3
937\& Steffen Beyer
938\& mailto:sb@engelschall.com
939\& http://www.engelschall.com/u/sb/download/
940.Ve
941.SH "COPYRIGHT"
942.IX Header "COPYRIGHT"
943Copyright (c) 2000 \- 2002 by Steffen Beyer. All rights reserved.
944.SH "LICENSE"
945.IX Header "LICENSE"
946This package is free software; you can redistribute it and/or
947modify it under the same terms as Perl itself, i.e., under the
948terms of the \*(L"Artistic License\*(R" or the \*(L"\s-1GNU\s0 General Public License\*(R".
949.PP
950Please refer to the files \*(L"Artistic.txt\*(R" and \*(L"\s-1GNU_GPL\s0.txt\*(R"
951in this distribution for details!
952.SH "DISCLAIMER"
953.IX Header "DISCLAIMER"
954This package is distributed in the hope that it will be useful,
955but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of
956\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0.
957.PP
958See the \*(L"\s-1GNU\s0 General Public License\*(R" for more details.