Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Date / Calendar.pod
CommitLineData
86530b38
AT
1
2=head1 NAME
3
4Date::Calendar - Calendar objects for different holiday schemes
5
6=head1 MOTTO
7
8There is more than one way to do it - this is just one of them!
9
10=head1 PREFACE
11
12Basically, Date::Calendar is just a caching proxy class for
13Date::Calendar::Year objects, which are embedded in each
14Date::Calendar object.
15
16However, and in contrast to Date::Calendar::Year methods, Date::Calendar
17methods permit calculations spanning an arbitrary number of years, without
18loss of efficiency.
19
20So you should usually use Date::Calendar and not Date::Calendar::Year,
21since that way you don't have to worry about calculations crossing year
22boundaries.
23
24Note however that Date::Calendar and Date::Calendar::Year can only deal
25with years lying within the range [1583..2299].
26
27=head1 SYNOPSIS
28
29 use Date::Calendar::Profiles qw( $Profiles );
30 use Date::Calendar;
31
32 $calendar_US_AZ = Date::Calendar->new( $Profiles->{'US-AZ'} [,LANG] );
33 $calendar_DE_SN = Date::Calendar->new( $Profiles->{'DE-SN'} [,LANG] );
34
35 $year_2000_US_AZ = $calendar_US_AZ->year( 2000 );
36 $year_2001_DE_SN = $calendar_DE_SN->year( 2001 );
37
38 @years = $calendar->cache_keys(); # returns list of year numbers
39 @years = $calendar->cache_vals(); # returns list of year objects
40
41 $calendar->cache_clr();
42 $calendar->cache_add(YEAR|DATE,...);
43 $calendar->cache_del(YEAR|DATE,...);
44
45 $index = $calendar->date2index(YEAR,MONTH,DAY|DATE);
46
47 @names = $calendar->labels(YEAR,MONTH,DAY|DATE);
48 @holidays = $calendar->labels();
49 $holidays = $calendar->labels();
50
51 @dates = $calendar->search(PATTERN);
52 $dates = $calendar->search(PATTERN);
53
54 $days = $calendar->delta_workdays(YEAR1,MONTH1,DAY1|DATE1
55 ,YEAR2,MONTH2,DAY2|DATE2
56 ,FLAG1,FLAG2);
57
58 ($date,$rest) = $calendar->add_delta_workdays(YEAR,MONTH,DAY|DATE
59 ,DELTA);
60 $date = $calendar->add_delta_workdays(YEAR,MONTH,DAY|DATE
61 ,DELTA);
62
63 $flag = $calendar->is_full(YEAR,MONTH,DAY|DATE);
64 $flag = $calendar->is_half(YEAR,MONTH,DAY|DATE);
65 $flag = $calendar->is_work(YEAR,MONTH,DAY|DATE);
66
67=head1 INTERFACE
68
69Note that whenever a year number, a date, a time or a combined
70date and time are expected as input parameters by one of the
71methods of this class, you can always pass a Date::Calc[::Object]
72date object or an array reference (of an array of appropriate
73length) instead!
74
75See L<Date::Calc::Object(3)> for more details.
76
77So instead of calling a given method like this:
78
79 $object->method1( $year,$month,$day );
80 $object->method2( $year1,$month1,$day1, $year2,$month2,$day2 );
81 $object->method3( $year1, $year2, $year3 );
82
83You can also call it like so:
84
85 $object->method1( $date );
86 $object->method1( [1964,1,3] );
87
88 $object->method2( $year1,$month1,$day1, $date2 );
89 $object->method2( $date1, $year2,$month2,$day2 );
90 $object->method2( $date1, $date2 );
91 $object->method2( $year1,$month1,$day1, [2001,3,17] );
92 $object->method2( [1964,1,3], $year2,$month2,$day2 );
93 $object->method2( [1964,1,3], [2001,3,17] );
94 $object->method2( $date1, [2001,3,17] );
95 $object->method2( [1964,1,3], $date2 );
96
97 $object->method3( $year1, $date2, [2001,3,17] );
98
99And similarly if a time or a combined date and time are expected.
100
101If you substitute an expected year number by an anonymous array
102(this is the recommended way of writing date constants, for
103increased readability of your programs), it must contain three
104values, nevertheless (otherwise the use of an anonymous array
105would be pointless).
106
107Don't confuse year numbers and their substitutes (a date object
108or an array reference) with Date::Calendar::Year objects, which
109are a totally different thing!
110
111But incidentally C<:-)>, you may also pass a Date::Calendar::Year
112object whenever a year number is expected. However, and perhaps
113against your expectations at times, especially in conjunction
114with the method "cache_add()", only the year number from that
115object will be used, not the year object itself (the year
116object in question might be using the wrong profile!).
117
118Moreover, whenever a method of this class returns a date, it
119does so by returning a Date::Calc[::Object] date object.
120
121=head1 DESCRIPTION
122
123=over 2
124
125=item *
126
127C<$calendar = Date::Calendar-E<gt>new(PROFILE[,LANG]);>
128
129The first argument must be the reference of a hash,
130which contains a holiday scheme or "profile" to be used
131in all calculations involving the new calendar object.
132
133The second argument is optional, and must consist of
134the valid name or number of a language as provided by
135the Date::Calc(3) module if given.
136
137See L<Date::Calendar::Profiles(3)> and L<Date::Calendar::Year(3)>
138for more details about these arguments and about how
139to roll your own calendar profiles.
140
141The method creates a new calendar object for a given profile,
142i.e., a given location and its scheme of holidays (or a scheme
143of your own).
144
145This calendar object is a caching proxy object; it stores the
146reference of the given profile and contains a hash (the cache)
147of Date::Calendar::Year objects.
148
149=item *
150
151C<$year = $calendar-E<gt>year(YEAR|DATE);>
152
153This method returns a Date::Calendar::Year object for the given
154year and the profile that was associated with the given calendar
155object.
156
157If the cache in the given calendar object already contains an
158object for the requested year, the corresponding object reference
159is simply returned.
160
161If not, a new Date::Calendar::Year object is created using the
162profile that has been associated with the given calendar object.
163The new Date::Calendar::Year object is then stored in the calendar
164object's cache and its object reference is returned.
165
166A fatal "given year out of range" error will occur if the given
167year number lies outside the valid range of [1583..2299].
168
169=item *
170
171C<@years = $calendar-E<gt>cache_keys();>
172
173This method returns the list of B<YEAR NUMBERS> of the
174Date::Calendar::Year objects contained in the given
175calendar object's cache.
176
177=item *
178
179C<@years = $calendar-E<gt>cache_vals();>
180
181This method returns the list of B<OBJECT REFERENCES> of
182the Date::Calendar::Year objects contained in the given
183calendar object's cache.
184
185=item *
186
187C<$calendar-E<gt>cache_clr();>
188
189This method clears the entire cache of the given calendar
190object (by destroying the cache hash and creating a new one).
191
192=item *
193
194C<$calendar-E<gt>cache_add(YEAR|DATE,...);>
195
196Roughly, this method is a shortcut for
197
198 for $year (@list)
199 {
200 $calendar->year($year);
201 }
202
203=item *
204
205C<$calendar-E<gt>cache_del(YEAR|DATE,...);>
206
207This method removes the Date::Calendar::Year objects whose
208year numbers are given from the cache of the given calendar
209object.
210
211Year numbers for which the calendar object's cache doesn't
212contain an entry are simply ignored.
213
214=item *
215
216C<$index = $calendar-E<gt>date2index(YEAR,MONTH,DAY|DATE);>
217
218This method converts a given date into the number of the day in
219that year (this is sometimes also referred to as the "julian"
220date), i.e., a number between 0 (for January 1st) and the number
221of days in the given year minus one, i.e., 364 or 365 (for
222December 31st).
223
224You may need this in order to access the bit vectors returned
225by the Date::Calendar::Year methods "vec_full()", "vec_half()"
226and "vec_work()".
227
228If the Date::Calendar::Year object for the given YEAR is not in
229the C<$calendar>'s cache yet, it will be created and added.
230
231An exception ("invalid date") is thrown if the given arguments
232do not constitute a valid date, or ("given year out of range
233[1583..2299]") if the given year lies outside of the permitted
234range.
235
236=item *
237
238C<@names = $calendar-E<gt>labels(YEAR,MONTH,DAY|DATE);>
239
240C<@holidays = $calendar-E<gt>labels();>
241
242C<$holidays = $calendar-E<gt>labels();>
243
244If any arguments are given, they are supposed to represent a
245date. In that case, a list of all labels (= names of holidays)
246associated with that date are returned. The first item returned
247is always the name of the day of week for that date. The
248corresponding year object for the given date's year is
249added to the calendar's cache first if necessary.
250
251If no arguments are given, the list of all available labels in
252all years that have previously been accessed in the given calendar
253(i.e., the years which are already in the given calendar's cache)
254is constructed. Note that this means that the returned list will
255be empty if there are no year objects in the given calendar's
256cache yet (!). The returned list does B<NOT> include any names
257of the days of week (which would be pointless in this case).
258
259Multiple labels are reported only once.
260
261Usually all years have the same set of labels, so it may seem
262superfluous to scan all the years in the cache instead of just
263one. But there may be exceptions, because it is possible to
264define calendar profiles which do not contain all possible
265holidays in every year. See L<Date::Calendar::Profiles(3)>
266and L<Date::Calendar::Year(3)> for more details.
267
268In list context, the resulting list itself is returned. In scalar
269context, the number of items in the resulting list is returned.
270
271=item *
272
273C<@dates = $calendar-E<gt>search(PATTERN);>
274
275C<$dates = $calendar-E<gt>search(PATTERN);>
276
277This method searches through all the labels in all years that
278have previously been accessed in the given calendar (i.e., the
279years which are already in the given calendar's cache) and
280returns a list of date objects with all dates whose labels
281match the given pattern.
282
283(Use the methods "cache_clr()", "cache_add()" and "cache_del()"
284in order to put the year numbers you want into the calendar
285object's cache, or to make sure it only contains the year
286numbers you want to search.)
287
288Note that this is a simple, case-insensitive substring search,
289B<NOT> a full-fledged regular expression search!
290
291The result is guaranteed to be sorted chronologically.
292
293In scalar context, only the number of items in the resulting list
294is returned, instead of the resulting list itself (as in list context).
295
296=item *
297
298C<$days = $calendar-E<gt>delta_workdays(YEAR1,MONTH1,DAY1, YEAR2,MONTH2,DAY2, FLAG1,FLAG2);>
299
300C<$days = $calendar-E<gt>delta_workdays(DATE1,DATE2,FLAG1,FLAG2);>
301
302This method calculates the number of work days (i.e., the number
303of days, but excluding all holidays) between two dates.
304
305In other words, this method is equivalent to the "Delta_Days()"
306function of the Date::Calc module, except that it disregards
307holidays in its counting.
308
309The two flags indicate whether the start and end dates should be
310included in the counting (that is, of course, only in case they
311aren't holidays), or not.
312
313It is common, for example, that you want to know how many work
314days are left between the current date and a given deadline.
315
316Typically, you will want to count the current date but not the
317deadline's date. So you would specify "true" ("1") for FLAG1
318and "false" ("0") for FLAG2 in order to achieve that.
319
320In other words, a value of "true" means "including this date",
321a value of "false" means "excluding this date".
322
323As with the "Delta_Days()" function from the Date::Calc module,
324the dates have to be given in chronological order to yield a
325positive result. If the dates are reversed, the result will
326be negative.
327
328The parameter FLAG1 is associated with the first given date,
329the parameter FLAG2 with the second given date (regardless
330of whether the dates are in chronological order or not).
331
332An exception ("invalid date") is raised if either of the two
333date arguments does not constitute a valid date.
334
335=item *
336
337C<($date,$rest) = $calendar-E<gt>add_delta_workdays(YEAR,MONTH,DAY, DELTA);>
338
339C<($date,$rest) = $calendar-E<gt>add_delta_workdays(DATE,DELTA);>
340
341C<$date = $calendar-E<gt>add_delta_workdays(YEAR,MONTH,DAY, DELTA);>
342
343C<$date = $calendar-E<gt>add_delta_workdays(DATE,DELTA);>
344
345This method is the equivalent of the "Add_Delta_Days()" function
346from the Date::Calc module, except that it adds work days and
347skips holidays.
348
349In other words, you can add or subtract a number of work days
350"DELTA" to/from a given date and get a new date as the result
351(as a Date::Calc object).
352
353You add days (i.e., you go forward in time) with a positive
354offset "DELTA", and you subtract days (i.e., you go backwards
355in time) with a negative offset.
356
357Note that an exception ("invalid date") is raised if the
358given date argument does not constitute a valid date.
359
360In scalar context, the method just returns the resulting date
361object, whereas in list context the method not only returns the
362new date, but also a "rest". This rest is useful for cases in
363which your profile contains "half" holidays, or when you add
364or subtract fractions of a day.
365
366Sometimes it is not possible to accomodate the requested number
367of work days, and a rest remains.
368
369This rest can currently only assume the value "0.0" (zero),
370"-0.5" (minus one half) or "0.5" (one half), provided you
371use only integral or multiples of 0.5 as offsets. A rest
372of zero indicates that the calculation yielded an exact
373result. If the rest is 0.5 or -0.5, this is to be interpreted
374as "the resulting date at 12:00 o'clock", instead of as "the
375resulting date at 0:00 o'clock".
376
377The rest is always positive (or zero) if the offset "DELTA"
378is positive (or zero), and always negative (or zero) if the
379offset is negative (or zero).
380
381Example:
382
383 #!perl
384 use Date::Calendar;
385 use Date::Calendar::Profiles qw( $Profiles );
386 $year = shift;
387 $cal = Date::Calendar->new( $Profiles->{'sdm-MUC'} );
388 ($date,$rest) = $cal->add_delta_workdays($year,1,3, -3);
389 $date->date_format(1);
390 print "\$date = $date, \$rest = $rest.\n";
391 __END__
392
393This program calculates "January 3rd of the given year minus
3943 work days":
395
396 > perl test.pl 2001
397 $date = 28-Dec-2000, $rest = 0.
398 > perl test.pl 2002
399 $date = 28-Dec-2001, $rest = -0.5.
400
401Note that December 31st is a "half" holiday in 2001 for the
402calendar profile used in this example.
403
404You can easily verify the results above with the help of the
405"calendar.cgi" CGI script or the "linearcal.pl" script from
406the "examples" subdirectory in the Date::Calc distribution.
407
408=item *
409
410C<$flag = $calendar-E<gt>is_full(YEAR,MONTH,DAY|DATE);>
411
412This method returns "true" ("1") if the bit corresponding to
413the given date is set in the bit vector representing "full"
414holidays, and "false" ("0") otherwise.
415
416I.e., the method returns "true" if the given date is a (full)
417holiday (according to the calendar profile associated with the
418given calendar object).
419
420The corresponding Date::Calendar::Year object is created first
421and stored in the calendar object's cache if necessary (if it's
422not already there).
423
424Note that you can get a reference to this bit vector (in order
425to use this bit vector in bit vector operations) as follows:
426
427 $vec_full = $calendar->year($year)->vec_full();
428
429The number of bits in this bit vector is the same as the number
430of days in the given year "C<$year>", which you can retrieve
431through either "C<$days = $vec_full-E<gt>Size();>" or
432"C<$days = $year-E<gt>val_days();>".
433
434See L<Date::Calendar::Year(3)> and L<Bit::Vector(3)> for more
435details.
436
437=item *
438
439C<$flag = $calendar-E<gt>is_half(YEAR,MONTH,DAY|DATE);>
440
441This method returns "true" ("1") if the bit corresponding to
442the given date is set in the bit vector representing "half"
443holidays, and "false" ("0") otherwise.
444
445I.e., the method returns "true" if the given date is a half
446holiday (according to the calendar profile associated with the
447given calendar object).
448
449Note that if a date is a "full" holiday, the "half" bit is
450never set, even if you try to do so in your calendar profile,
451on purpose or by accident.
452
453The corresponding Date::Calendar::Year object is created first
454and stored in the calendar object's cache if necessary (if it's
455not already there).
456
457Note that you can get a reference to this bit vector (in order
458to use this bit vector in bit vector operations) as follows:
459
460 $vec_half = $calendar->year($year)->vec_half();
461
462The number of bits in this bit vector is the same as the number
463of days in the given year "C<$year>", which you can retrieve
464through either "C<$days = $vec_half-E<gt>Size();>" or
465"C<$days = $year-E<gt>val_days();>".
466
467See L<Date::Calendar::Year(3)> and L<Bit::Vector(3)> for more
468details.
469
470=item *
471
472C<$flag = $calendar-E<gt>is_work(YEAR,MONTH,DAY|DATE);>
473
474This method returns "true" ("1") if the bit corresponding to
475the given date is set in the bit vector used to perform all
476sorts of calculations, and "false" ("0") otherwise.
477
478The corresponding Date::Calendar::Year object is created first
479and stored in the calendar object's cache if necessary (if it's
480not already there).
481
482B<BEWARE> that the "work" in this method's name does B<NOT>
483come from "work days"!
484
485It comes from the fact that the corresponding bit vector can
486be used for any "work" that you need to do. In other words,
487it's a "work space".
488
489Therefore, this bit vector might contain about everything you
490could imagine - including a bit pattern which marks all "work
491days" with set bits, if it so happens!
492
493But you better don't rely on it, unless you put the bit pattern
494there yourself in the first place.
495
496Note that you can get a reference to this bit vector (in order
497to fill it with any bit pattern you like) as follows:
498
499 $vec_work = $calendar->year($year)->vec_work();
500
501The number of bits in this bit vector is the same as the number
502of days in the given year "C<$year>", which you can retrieve
503through either "C<$days = $vec_work-E<gt>Size();>" or
504"C<$days = $year-E<gt>val_days();>".
505
506See L<Date::Calendar::Year(3)> and L<Bit::Vector(3)> for more
507details.
508
509=back
510
511=head1 SEE ALSO
512
513Date::Calendar::Year(3), Date::Calendar::Profiles(3),
514Date::Calc::Object(3), Date::Calc(3), Bit::Vector(3).
515
516=head1 VERSION
517
518This man page documents "Date::Calendar" version 5.3.
519
520=head1 AUTHOR
521
522 Steffen Beyer
523 mailto:sb@engelschall.com
524 http://www.engelschall.com/u/sb/download/
525
526=head1 COPYRIGHT
527
528Copyright (c) 2000 - 2002 by Steffen Beyer. All rights reserved.
529
530=head1 LICENSE
531
532This package is free software; you can redistribute it and/or
533modify it under the same terms as Perl itself, i.e., under the
534terms of the "Artistic License" or the "GNU General Public License".
535
536Please refer to the files "Artistic.txt" and "GNU_GPL.txt"
537in this distribution for details!
538
539=head1 DISCLAIMER
540
541This package is distributed in the hope that it will be useful,
542but WITHOUT ANY WARRANTY; without even the implied warranty of
543MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
544
545See the "GNU General Public License" for more details.
546