| Date-Pcalc documentation | view source | Contained in the Date-Pcalc distribution. |
Date::Pcalendar::Year - Implements embedded "year" objects for Date::Pcalendar
There is more than one way to do it - this is just one of them!
Note that Date::Pcalendar::Year (and Date::Pcalendar) can only deal with years lying within the range [1583..2299].
use Date::Pcalendar::Year qw( check_year empty_period );
use Date::Pcalendar::Year qw( :all ); # same as above
check_year(YEAR|DATE); # dies if year < 1583 or year > 2299
empty_period(); # warns about empty interval if $^W is set
$index = $year->date2index(YEAR,MONTH,DAY|DATE);
$date = $year->index2date(INDEX);
use Date::Pcalendar::Profiles qw( $Profiles );
$year_2000_US_FL = Date::Pcalendar::Year->new( 2000, $Profiles->{'US-FL'} [,LANG[,WEEKEND]] );
$year_2001_DE_NW = Date::Pcalendar::Year->new( 2001, $Profiles->{'DE-NW'} [,LANG[,WEEKEND]] );
$year = Date::Pcalendar::Year->new( 2001, {} );
$year->init( 2002, $Profiles->{'DE-SN'} [,LANG[,WEEKEND]] );
$vector = $year->vec_full(); # vector of full holidays
$vector = $year->vec_half(); # vector of half holidays
$vector = $year->vec_work(); # NOT a vector of workdays but a workspace!
$size = $year->val_days(); # number of days in that year, size of vectors
$base = $year->val_base(); # number of days for [year,1,1] since [1,1,1]
$number = $year->val_year(); # the year's number itself
$number = $year->year(); # alias for val_year()
@names = $year->labels(YEAR,MONTH,DAY|DATE);
@holidays = $year->labels();
$holidays = $year->labels();
@dates = $year->search(PATTERN);
$dates = $year->search(PATTERN);
$hashref = $year->tags(YEAR,MONTH,DAY|DATE);
$hashref = $year->tags(INDEX);
$days = $year->delta_workdays(YEAR,MONTH1,DAY1|DATE1
,YEAR,MONTH2,DAY2|DATE2
,FLAG1,FLAG2);
($date,$rest,$sign) = $year->add_delta_workdays(YEAR,MONTH,DAY|DATE
,DELTA,SIGN);
$flag = $year->is_full(YEAR,MONTH,DAY|DATE);
$flag = $year->is_half(YEAR,MONTH,DAY|DATE);
$flag = $year->is_work(YEAR,MONTH,DAY|DATE);
Note that whenever a year number, a date, a time or a combined date and time are expected as input parameters by one of the methods of this class, you can always pass a Date::Pcalc[::Object] date object or an array reference (of an array of appropriate length) instead!
See Date::Pcalc::Object(3) for more details.
So instead of calling a given method like this:
$object->method1( $year,$month,$day ); $object->method2( $year1,$month1,$day1, $year2,$month2,$day2 ); $object->method3( $year1, $year2, $year3 );
You can also call it like so:
$object->method1( $date ); $object->method1( [1964,1,3] ); $object->method2( $year1,$month1,$day1, $date2 ); $object->method2( $date1, $year2,$month2,$day2 ); $object->method2( $date1, $date2 ); $object->method2( $year1,$month1,$day1, [2001,3,17] ); $object->method2( [1964,1,3], $year2,$month2,$day2 ); $object->method2( [1964,1,3], [2001,3,17] ); $object->method2( $date1, [2001,3,17] ); $object->method2( [1964,1,3], $date2 ); $object->method3( $year1, $date2, [2001,3,17] );
And similarly if a time or a combined date and time are expected.
If you substitute an expected year number by an anonymous array (this is the recommended way of writing date constants, for increased readability of your programs), it must contain three values, nevertheless (otherwise the use of an anonymous array would be pointless).
Don't confuse year numbers and their substitutes (a date object or an array reference) with Date::Pcalendar::Year objects, which are a totally different thing!
But incidentally :-), you may also pass a Date::Pcalendar::Year
object whenever a year number is expected. However, and perhaps
against your expectations at times, only the year number from
that object will be used, not the year object itself (the year
object in question might be using the wrong profile!).
Moreover, whenever a method of this class returns a date, it does so by returning a Date::Pcalc[::Object] date object.
Each Date::Pcalendar::Year object consists mainly of three bit vectors, plus some administrative attributes, all stored in a (blessed) hash.
All three bit vectors contain as many bits as there are days in the corresponding year, i.e., either 365 or 366.
The first bit vector, called "FULL", contains set bits for Saturdays, Sundays and all "full" legal holidays (i.e., days off, on which you usually do not work).
The second bit vector, called "HALF", contains set bits for all "half" holidays, i.e., holidays where you get only half a day off from work.
The third and last bit vector, called "WORK", is used as a workspace, in which various calculations are performed throughout this module.
Its name does NOT come from "working days" (as you might think), but from "workspace".
It only so happens that it is used to calculate the working days sometimes, at some places in this module.
But you are free to use it yourself, for whatever calculation you would like to carry out yourself.
The two other bit vectors, "FULL" and "HALF", should never be changed, unless you know EXACTLY what you're doing!
Functions
check_year(YEAR);
empty_period();
$^W" is true).
Methods
$index = $year->date2index(YEAR,MONTH,DAY|DATE);
$date = $year->index2date(INDEX);
[0..364] or [0..365].
$year_2000_US_FL = Date::Pcalendar::Year->new( 2000, $Profiles->{'US-FL'} [,LANG[,WEEKEND]] );
$year_2001_DE_NW = Date::Pcalendar::Year->new( 2001, $Profiles->{'DE-NW'} [,LANG[,WEEKEND]] );
$year = Date::Pcalendar::Year->new( 2001, {} );
1..7 are given,
they will be ignored.
$year->init( 2002, $Profiles->{'DE-SN'} [,LANG[,WEEKEND]] );
- fixed dates
(like New Year, or first of January),
- dates relative to Easter Sunday
(like Ascension = Easter Sunday + 39 days), and
- the 1st, 2nd, 3rd, 4th or last
of a given day of week in a given month
(like "the 4th Thursday of November", or Thanksgiving).
:-)
- Fixed dates:
"Christmas" => "24.12", # European format (day, month)
"Christmas" => "24.12.",
"Christmas" => "24Dec",
"Christmas" => "24.Dec",
"Christmas" => "24Dec.",
"Christmas" => "24.Dec.",
"Christmas" => "24-12",
"Christmas" => "24-12-",
"Christmas" => "24-Dec",
"Christmas" => "24-Dec-",
"Christmas" => "12/25", # American format (month, day)
"Christmas" => "Dec25",
"Christmas" => "Dec/25",
- Dates relative to Easter Sunday:
"Ladies' Carnival" => "-52",
"Carnival Monday" => "-48",
"Mardi Gras" => "-47",
"Ash Wednesday" => "-46",
"Palm Sunday" => "-7",
"Maundy Thursday" => "-3",
"Good Friday" => "-2",
"Easter Sunday" => "+0",
"Easter Monday" => "+1",
"Ascension" => "+39",
"Whitsunday" => "+49",
"Whitmonday" => "+50",
"Corpus Christi" => "+60",
- The 1st, 2nd, 3rd, 4th or last day of week:
"Thanksgiving" => "4Thu11",
"Thanksgiving" => "4/Thu/Nov",
"Columbus Day" => "2/Mon/Oct",
"Columbus Day" => "2/Mon/10",
"Columbus Day" => "2/1/Oct",
"Columbus Day" => "2/1/10",
"Memorial Day" => "5/Mon/May", # LAST Monday of May
"Christmas" => ":24.12.", # only half a day off
"Valentine's Day" => "#Feb/14", # not an official holiday
...
"My special holiday" => "01-11",
"My special holiday" => "02-11",
...
$defaults =
{
"Holiday #1" => "01-01",
"Holiday #2" => "02-02",
"Holiday #3" => "03-03"
};
$variant1 =
{
%$defaults,
"Holiday #2" => "09-02",
"Holiday #4" => "04-04"
};
$vector = $year->vec_full();
$vector = $year->vec_half();
$vector = $year->vec_work();
$days = $vector->Size();" or
"$days = $year->val_days();". $size = $year->val_days();
$base = $year->val_base();
Date_to_Days($year->val_year(),1,1)", or in other words,
the number of days between January 1st of the year 1 and January
1st of the given year, plus one.
$number = $year->val_year();
$number = $year->year();
@names = $year->labels(YEAR,MONTH,DAY|DATE);
@holidays = $year->labels();
$holidays = $year->labels();
@dates = $year->search(PATTERN);
$dates = $year->search(PATTERN);
$hashref = $year->tags(YEAR,MONTH,DAY|DATE);
$hashref = $year->tags(INDEX);
0 => commemorative day
1 => "half" holiday
2 => "full" holiday
3 => both a "half" and a "full" holiday
$days = $year->delta_workdays(YEAR,MONTH1,DAY1, YEAR,MONTH2,DAY2, FLAG1,FLAG2);
$days = $year->delta_workdays(DATE1,DATE2,FLAG1,FLAG2);
($date,$rest,$sign) = $year->add_delta_workdays(YEAR,MONTH,DAY, DELTA, SIGN);
($date,$rest,$sign) = $year->add_delta_workdays(DATE,DELTA,SIGN);
$flag = $year->is_full(YEAR,MONTH,DAY|DATE);
$flag = $year->is_half(YEAR,MONTH,DAY|DATE);
$flag = $year->is_work(YEAR,MONTH,DAY|DATE);
$year", which you can retrieve
through either "$days = $year->vec_work->Size();"
or "$days = $year->val_days();".
Bit::Vector(3), Date::Pcalendar(3), Date::Pcalendar::Profiles(3), Date::Pcalc::Object(3), Date::Pcalc(3), Date::Calc::Util(3).
The method "add_delta_workdays()" is known to produce results which are sometimes off by one working day when a negative offset is used. As a workaround, try to add one working day first and then subtract one working day more than initially intended. See also the file "examples/bug.pl" for how to do this.
This man page documents "Date::Pcalendar::Year" version 6.1.
Steffen Beyer mailto:STBEY@cpan.org http://www.engelschall.com/u/sb/download/
Copyright (c) 2000 - 2009 by Steffen Beyer. All rights reserved.
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".
Please refer to the files "Artistic.txt" and "GNU_GPL.txt" in this distribution for details!
This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the "GNU General Public License" for more details.
| Date-Pcalc documentation | view source | Contained in the Date-Pcalc distribution. |