Date::C...rofiles(3)
π Date::Calendar::Profiles(3) β the glow-up
okay so bestie, this is a manual page for Date::Calendar::Profiles(3), and it's genuinely one of those "here's a bunch of ready-made holiday schemes so you don't have to build them from scratch" situations. it's giving "starter pack" energy, and honestly? iconic.
β¨ NAME β¨
Date::Calendar::Profiles β some sample profiles for Date::Calendar and Date::Calendar::Year. literally just a little collection of holiday schemes you can borrow. π
πΈ SYNOPSIS πΈ
first up, using Date::Calendar:
use Date::Calendar::Profiles qw( $Profiles );
use Date::Calendar;
$cal_US_AK = Date::Calendar->new( $Profiles->{'US-AK'} [,LANG[,WEEKEND]] );
$cal_DE_BY = Date::Calendar->new( $Profiles->{'DE-BY'} [,LANG[,WEEKEND]] );
or, if you're more of a Date::Calendar::Year girlie:
use Date::Calendar::Profiles qw( $Profiles );
use Date::Calendar::Year;
$year_2000_US_FL = Date::Calendar::Year->new( 2000, $Profiles->{'US-FL'} [,LANG[,WEEKEND]] );
$year_2001_DE_NW = Date::Calendar::Year->new( 2001, $Profiles->{'DE-NW'} [,LANG[,WEEKEND]] );
and also β yes, there's an and also β you can pull in the utility subs:
use Date::Calendar::Profiles
qw(
&Previous_Friday
&Next_Monday
&Next_Monday_or_Tuesday
&Nearest_Workday
&Sunday_to_Monday
&Advent1
&Advent2
&Advent3
&Advent4
&Advent
);
π¦ PREFACE π¦
so this module hands you some sample profiles (that's holiday schemes, iykyk) for use with the Date::Calendar(3) and Date::Calendar::Year(3) modules. π«Ά
you are not required to use these at all β you can always roll your own, and bestie, it's very easy. see the section "HOW TO ROLL YOUR OWN" below for instructions, and honestly just treat the profiles in here as examples, that's the whole vibe.
the author is very clear about this: they intend not to make any fixes to any of the calendar profiles in this module anymore unless there are VERY compelling reasons to do so. these profiles are merely meant as examples. periodt. π
the suggested way of using these profiles is to copy them to your own code and then modify them as needed. otherwise lots of people could be negatively affected if any changes got made to a profile someone has been using for years β and we do not want that energy. π
so: any improvements are therefore left as an exercise to the inclined reader. π§
π DESCRIPTION π
the method init() in module Date::Calendar::Year(3) is responsible for parsing the calendar schemes contained here in the Date::Calendar::Profiles module. it's the main character of this whole operation, lowkey.
this method offers a "mini-language" that lets you specify common date formulas β like, for instance, a simple fixed date (in various different formats, e.g. american or european), or things like "the second Sunday of May" (Mother's Day), or "Easter Sunday minus 46 days" (Ash Wednesday), to cite just a few. highkey clever.
see the section "DATE FORMULA SYNTAX" below for more details.
there are some more complicated formulas, however, which cannot be expressed in such simple terms. π
the rule that if a holiday falls on a weekend, it will be substituted by either the adjacent Friday or Monday (whichever lies closer) β that's an example of this. it's giving "we need a bigger toolbox".
in order to be able to deal with such formulas, and in order to be as flexible as possible, the init() method offers the possibility of using callback functions to deal with such dates and formulas. slay.
see the section "CALLBACK INTERFACE" below for more details on this topic.
in order to assist you with more common cases of odd formulas, the module Date::Calendar::Profiles exports the following utility subroutines (which are meant to be used as "filters" in callback functions of your own):
($year,$month,$day[,ANYTHING]) = Previous_Friday($year,$month,$day[,ANYTHING]);
if the given date falls on a Saturday or Sunday, this function changes the date to the adjacent Friday before that, and returns this new date. β
otherwise the given date is returned unchanged.
the rest of the input parameters, if any, are simply copied to the output.
($year,$month,$day[,ANYTHING]) = Next_Monday($year,$month,$day[,ANYTHING]);
if the given date falls on a Saturday or Sunday, this function changes the date to the adjacent Monday after that, and returns this new date. π
otherwise the given date is returned unchanged.
the rest of the input parameters, if any, are simply copied to the output.
($year,$month,$day[,ANYTHING]) = Next_Monday_or_Tuesday($year,$month,$day[,ANYTHING]);
if the given date falls on a Saturday, the date of the next Monday (after that weekend) is returned.
if the given date falls on a Sunday, the date of the next Tuesday (after that weekend) is returned.
if the given date falls on a Monday, the date of the next Tuesday (the day after the Monday) is returned.
otherwise the given date is returned unchanged.
the rest of the input parameters, if any, are simply copied to the output.
this function is used for the second of two adjacent holidays, where the first holiday obeys the "Next Monday" rule (see the description of the function immediately above). π
examples of this are Christmas and Boxing Day, among others.
when the first holiday falls on Friday, the second one falls on Saturday and is substituted by Monday.
when the first holiday falls on a Saturday, the second one falls on Sunday, so the first holiday is substituted by Monday and the second one by Tuesday.
when the first holiday falls on a Sunday, the second one falls on a Monday. therefore the first holiday is substituted by Monday, and consequently the second holiday must be substituted by Tuesday.
or, in other terms:
Fri Sat => Fri Mon
Sat Sun => Mon Tue
Sun Mon => Mon Tue
note that there is no filter subroutine yet for the second of two adjacent holidays when the first holiday obeys the "Nearest Workday" rule (see the function described immediately below), i.e.,
Fri Sat => Fri Mon
Sat Sun => Fri Mon
Sun Mon => Mon Tue
this is left as an excercise to the inclined reader. ":-)" π (yes, that's spelled "excercise" in the original, we're keeping the facts, not the vibes, omg)
($year,$month,$day[,ANYTHING]) = Nearest_Workday($year,$month,$day[,ANYTHING]);
if the given date falls on a Saturday, this function returns the date of the Friday on the day before. π
if the given date falls on a Sunday, this function returns the date of the Monday on the day after.
otherwise the given date is returned unchanged.
the rest of the input parameters, if any, are simply copied to the output.
($year,$month,$day[,ANYTHING]) = Sunday_to_Monday($year,$month,$day[,ANYTHING]);
if the given date falls on a Sunday, this function returns the date of the Monday on the day after. π
otherwise the given date is returned unchanged.
the rest of the input parameters, if any, are simply copied to the output.
the typical use of these filter subroutines is in a "return" statement at the end of callback functions of your own, when you already have calculated the holiday in question and only need to adjust it according to the rule implemented by the filter subroutine in question. so neat. β¨
see also the implementation of the Date::Calendar::Profiles module for examples of how to use these functions.
π DATE FORMULA SYNTAX π
okay this is the part where it gets fun β here's the whole mini-language, laid out exactly:
- 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
- half holidays, commemorative days:
"Christmas" => ":24.12.", # only half a day off
"Valentine's Day" => "#Feb/14", # not an official holiday
π CALLBACK INTERFACE π
the interface of the callback functions to use with the init() method of the Date::Calendar::Year(3) module is very simple β like, refreshingly simple, ngl.
the callback function receives two arguments when called:
- first, the year number for which the holiday is to be calculated
- second, the name (the
"label") of the holiday in question (which serves as key in the hash of a holiday scheme)
this second parameter allows you to use the same callback function for different holidays, which might be more practical (than separate callback functions) if for instance you have a set of similar holidays to calculate, like for instance the four Sundays before Christmas ("Advent"). π―οΈ
the callback function "Advent()" (exported by the Date::Calendar::Profiles module) exemplifies this technique. iconic behaviour, honestly.
the callback function is expected to return a list "($year,$month,$day)" with the exact date of the holiday (the year number in the output must of course match the year number passed as parameter). π
β οΈ a fatal error occurs if the returned list does not constitute a valid date, in the requested year. no cap, that's a hard fail.
optionally, the callback function may return a fourth value (after the date) containing a string, which may be either "#" or ":". π
the string "#" signifies that the date in question is a purely commemorative date, i.e., that you don't get a day off from work on that day.
the string ":" means that the date in question is a "half" holiday, i.e., a day on which you get half a day off from work.
in case the holiday in question was not observed or did not exist in the requested year, the callback function may also return an empty list. this will cause the init() method to simply drop this holiday for that year. clean. π¦
the module Date::Calendar::Profiles exports the sample callback functions "Advent1()", "Advent2()", "Advent3()", "Advent4()" and "Advent()", which might assist you in rolling your own profiles. π₯
π HOW TO ROLL YOUR OWN π
Okay bestie, so here's the tea β every calendar profile (aka a holiday scheme, your own personal vibe of a year) is just a hash.
The name of the holiday (like "Christmas", for instance) is the key in this hash, so it has to be unique β unless you're deliberately overriding a default that was set earlier (but hold up, more on that below, don't scroll yet).
The value for each key is either a string, which specifies a simple date formula, or the reference of a callback function.
Peep the CALLBACK INTERFACE section above for how these callback functions work (in and out, the whole thing). And check DATE FORMULA SYNTAX above plus the description of the init() method in Date::Calendar::Year(3) for the exact syntax of date formula strings. β¨
BEWARE that if keys are not unique in the source code, later entries will overwrite previous ones! Like, literally:
...
"My special holiday" => "01-11",
"My special holiday" => "02-11",
...
That will NOT set two holidays with the same name, one on November first and the other on November second. You get only one, on November second. The first one? Gone. Deleted. Not invited to the party. π
So if you want to use sets of defaults and still be able to override a few of them, you have to FIRST include any hash containing the default definitions, and THEN write down your own definitions (check the Date::Calendar::Profiles module for examples of exactly this!), like so:
$defaults =
{
"Holiday #1" => "01-01",
"Holiday #2" => "02-02",
"Holiday #3" => "03-03"
};
$variant1 =
{
%$defaults,
"Holiday #2" => "09-02",
"Holiday #4" => "04-04"
};
This is simply because of the way hashes work in Perl. It's not being mean, it's just being Perl. π«Ά
Now let's say you want to write a profile containing all your relatives' and friends' birthdays or anniversaries. Honestly? Iconic use case.
Just go ahead and list them in your program, in any order you like, like this (for example):
$Birthdays =
{
"Spouse 1971" => "30.12.",
"Wedding Day 1992" => "01.09.",
"Valentine's Day" => "14.02.",
"Son Richard 1996" => "11.05.",
"Daughter Irene 1994" => "17.01.",
"Mom 1939" => "19.08.",
"Dad 1937" => "23.04.",
"Brother Timothy 1969" => "24.04.",
"Sister Catherine 1973" => "21.10.",
"Cousin Paul 1970" => "16.10.",
"Aunt Marjorie 1944" => "09.06.",
"Uncle George 1941" => "02.08.",
"Friend Alexander 1968" => "12.06.",
};
The year numbers after the names are not really necessary, but they let us display the person's current age. Omit the year number and we simply don't display the age. No year, no age reveal β your call bestie. π
Now to query this birthday database, we can use the following little program:
#!perl -w
use strict;
no strict "vars";
use Date::Calc qw(:all);
use Date::Calendar;
$Birthdays =
{
... # (see above)
};
@today = Today();
$calendar = Date::Calendar->new( $Birthdays );
$calendar->year( $today[0] );
foreach $key (@ARGV)
{
if (@list = $calendar->search( $key ))
{
foreach $date (@list)
{
@labels = $calendar->labels( $date );
$dow = shift(@labels);
# More than one person might have birthday on the same date:
$name = $key;
foreach $person (@labels)
{
if (index(lc($person),lc($key)) >= 0)
{
$name = $person;
last;
}
}
$delta = Delta_Days(@today, $date->date());
$age = '';
if ($name =~ s!\s*(\d+)\s*$!!)
{
$age = $today[0] - $1;
$age-- if ($delta > 0);
$age = sprintf(" (%2d years old)", $age);
}
printf
(
"%-20.20s: %+5d days => %3.3s %2d-%3.3s-%4d%s\n",
$name,
$delta,
$dow,
$date->day(),
Month_to_Text($date->month()),
$date->year(),
$age
);
}
}
else { print "No entry found in birthday list for '$key'!\n" }
}
__END__
Let's save this program as, say, birthday.pl. Slay. πΎ
Then we can query this birthday database by providing search strings on the command line, like this β and note that this is a (case-insensitive) substring search, NOT a regular expression match! (Big difference, don't come for me.)
> date
Wed Oct 3 18:05:45 CEST 2001
> perl birthday.pl wed spo
Wedding Day : -32 days => Sat 1-Sep-2001 ( 9 years old)
Spouse : +88 days => Sun 30-Dec-2001 (29 years old)
> perl birthday.pl son daug
Son Richard : -145 days => Fri 11-May-2001 ( 5 years old)
Daughter Irene : -259 days => Wed 17-Jan-2001 ( 7 years old)
> perl birthday.pl broth sist
Brother Timothy : -162 days => Tue 24-Apr-2001 (32 years old)
Sister Catherine : +18 days => Sun 21-Oct-2001 (27 years old)
> perl birthday.pl mom dad
Mom : -45 days => Sun 19-Aug-2001 (62 years old)
Dad : -163 days => Mon 23-Apr-2001 (64 years old)
> perl birthday.pl uncl aunt
Uncle George : -62 days => Thu 2-Aug-2001 (60 years old)
Aunt Marjorie : -116 days => Sat 9-Jun-2001 (57 years old)
> perl birthday.pl alex
Friend Alexander : -113 days => Tue 12-Jun-2001 (33 years old)
And to get the whole list, we can supply a substring which is contained in every name β which just so happens to be a blank (" "). Lil hack, lil genius move:
> perl birthday.pl ' '
Daughter Irene : -259 days => Wed 17-Jan-2001 ( 7 years old)
Valentine's Day : -231 days => Wed 14-Feb-2001
Dad : -163 days => Mon 23-Apr-2001 (64 years old)
Brother Timothy : -162 days => Tue 24-Apr-2001 (32 years old)
Son Richard : -145 days => Fri 11-May-2001 ( 5 years old)
Aunt Marjorie : -116 days => Sat 9-Jun-2001 (57 years old)
Friend Alexander : -113 days => Tue 12-Jun-2001 (33 years old)
Uncle George : -62 days => Thu 2-Aug-2001 (60 years old)
Mom : -45 days => Sun 19-Aug-2001 (62 years old)
Wedding Day : -32 days => Sat 1-Sep-2001 ( 9 years old)
Cousin Paul : +13 days => Tue 16-Oct-2001 (30 years old)
Sister Catherine : +18 days => Sun 21-Oct-2001 (27 years old)
Spouse : +88 days => Sun 30-Dec-2001 (29 years old)
By the way, a similar program ships in the examples subdirectory of the Date::Calc distribution, called anniversaries.pl. π
Also see the file EXAMPLES.txt in the distribution's main directory for a short description of that little script.
π SEE ALSO π
Date::Calendar(3), Date::Calendar::Year(3), Date::Calc::Object(3), Date::Calc(3), Date::Calc::Util(3).
Go read them, they're the whole friend group. π
π§ LIMITATIONS π§
The calendar profiles included in this module usually do not take historical irregularities into account (even though some do, specifically to show how this can be done). They only provide means for calculating regularly recurring events. So don't be relying on these profiles for historical faithfulness β that's not the assignment. π
π KNOWN BUGS π
The australian calendar profiles are known to contain wrong dates. Why? Because Australia decrees its holidays individually for each year, which makes calculating the holidays by way of a formula difficult β it's giving "make my life harder" energy. An effort to compare (and to correct) the current implementation with official documents (web pages) by the Australian authorities is under way. It hasn't been finished yet because it is very time-consuming. Respect the grind, but yeah, known issue. π
β VERSION β
This man page documents Date::Calendar::Profiles version 6.4.
π AUTHOR π
Steffen Beyer
mailto:STBEY@cpan.org
http://www.engelschall.com/u/sb/download/
π COPYRIGHT π
Copyright (c) 2000 - 2015 by Steffen Beyer. All rights reserved.
βοΈ LICENSE βοΈ
This package is free software; you can use, modify and redistribute it under the same terms as Perl itself β that is, at your option, under the terms either of the "Artistic License" or the "GNU General Public License".
The C library at the core of the module "Date::Calc::XS" can, at your discretion, also be used, modified and redistributed under the terms of the "GNU Library General Public License".
Please refer to the files "Artistic.txt", "GNU_GPL.txt" and "GNU_LGPL.txt" in the "license" subdirectory of this distribution for any details! π
πΈ DISCLAIMER πΈ
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.
β¨ That's the whole page bestie, you made it! β¨
This one's documented as Date::Calendar::Profiles version 6.4, shipped with perl v5.42.0, dated 2025-02-06. Take care of her, she's been around since 2000. π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Date-Calc 6.400.0-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms