| 1 |
# Copyright (c) 1995-2026 Sullivan Beck. All rights reserved. |
| 2 |
# This program is free software; you can redistribute it and/or modify it |
| 3 |
# under the same terms as Perl itself. |
| 4 |
|
| 5 |
=pod |
| 6 |
|
| 7 |
=head1 NAME |
| 8 |
|
| 9 |
Date::Manip::Holidays - describes holidays and events |
| 10 |
|
| 11 |
=head1 SYNOPSIS |
| 12 |
|
| 13 |
This describes the Holidays and Events sections of the config file, |
| 14 |
and how they are used. |
| 15 |
|
| 16 |
Holidays and events are specific days that are named. Holidays are |
| 17 |
used in business mode calculations, events are not. Events may be used |
| 18 |
for other calendaring operations. |
| 19 |
|
| 20 |
=head1 HOLIDAYS |
| 21 |
|
| 22 |
The holiday section of the config file is used to define holidays. Each |
| 23 |
line is of the form: |
| 24 |
|
| 25 |
STRING = HOLIDAY |
| 26 |
|
| 27 |
HOLIDAY is the name of the holiday or it can be blank. |
| 28 |
|
| 29 |
If HOLIDAY is blank, the holiday is unnamed, but still treated as a |
| 30 |
holiday. For example, in the US, the day after Thanksgiving is often |
| 31 |
a work holiday though it is not named. |
| 32 |
|
| 33 |
HOLIDAY should be unique in most cases. The only exception is if the |
| 34 |
holiday definition is complex enough that it is impossible to describe |
| 35 |
it with one STRING. In this case, multiple lines may be given with |
| 36 |
different values of STRING but the same value for HOLIDAY, and in these |
| 37 |
cases, the first STRING that matches a given year will be used. This |
| 38 |
situation is described in more detail below. |
| 39 |
|
| 40 |
NOTE: It is not allowed to have unnamed holidays that require multiple |
| 41 |
definitions, so a name will have to be assigned in that case. |
| 42 |
|
| 43 |
STRING is a string which can be parsed to give a valid date. It can be any |
| 44 |
of the following forms: |
| 45 |
|
| 46 |
=over 4 |
| 47 |
|
| 48 |
=item B<A full date> |
| 49 |
|
| 50 |
Specific holidays can be set which occur only a single time. |
| 51 |
|
| 52 |
May 5, 2000 = A one-time-only holiday |
| 53 |
|
| 54 |
Any format parseable by C<Date::Manip::Date::parse_date> can be used. |
| 55 |
|
| 56 |
There is one caveat to using a full date. Date::Manip assumes that |
| 57 |
most holidays will appear once per year, so if you were to explicitly |
| 58 |
defined New Years (observed) as: |
| 59 |
|
| 60 |
2004-12-31 = New Year's Day |
| 61 |
|
| 62 |
then it would assume that it had found the occurrence of New Year's for |
| 63 |
2004 when in fact, this is the 2005 occurrence. |
| 64 |
|
| 65 |
Full date specifications should only be used as a last resort, and |
| 66 |
probably only if you will explicitly specify all occurrence of the |
| 67 |
holiday. |
| 68 |
|
| 69 |
=item B<A date without a year> |
| 70 |
|
| 71 |
Some holidays occur every year on the same day. These can be defined |
| 72 |
using the simple lines: |
| 73 |
|
| 74 |
Jan 1 = New Year's Day |
| 75 |
Jul 4th = Independence Day |
| 76 |
fourth Thu in Nov = Thanksgiving |
| 77 |
|
| 78 |
These dates must be written in a form which can be parsed as a full |
| 79 |
date by simply adding the year to the end of the string. Please refer |
| 80 |
to the L<Date::Manip::Date> documentation to see what forms will |
| 81 |
work. ISO 8601 dates will not work since the year comes first. |
| 82 |
|
| 83 |
Any format parseable by C<Date::Manip::Date::parse_date> which allows the |
| 84 |
year to be at the end can be used. |
| 85 |
|
| 86 |
=item B<Recurrence> |
| 87 |
|
| 88 |
The dates can be specified using recurrences: |
| 89 |
|
| 90 |
1*0:0:0:0:0:0*EASTER = Easter |
| 91 |
1*11:0:11:0:0:0*DWD = Veteran's Day |
| 92 |
1*11:4:4:0:0:0 = Thanksgiving |
| 93 |
1*11:4:4:0:0:0*FD1 = Day after Thanksgiving |
| 94 |
|
| 95 |
In cases where you are interested in business type calculations, you'll |
| 96 |
want to define most holidays using recurrences, since they can define |
| 97 |
when a holiday is celebrated in the financial world. For example, |
| 98 |
Christmas might be defined as: |
| 99 |
|
| 100 |
Dec 25 = Christmas |
| 101 |
|
| 102 |
but if it falls on a weekend, there won't be a business holiday |
| 103 |
associated with it. It could be defined using a recurrence: |
| 104 |
|
| 105 |
1*12:0:24:0:0:0*DWD = Christmas |
| 106 |
|
| 107 |
so that if Christmas falls on a weekend, a holiday will be taken |
| 108 |
on the Friday before or the Monday after the weekend. |
| 109 |
|
| 110 |
You can use the fully specified format of a recurrence: |
| 111 |
|
| 112 |
1*2:0:1:0:0:0***Jan 1 1999*Dec 31 2002 = Feb 2 from 1999-2002 |
| 113 |
|
| 114 |
=back |
| 115 |
|
| 116 |
=head1 OTHER HOLIDAY CONSIDERATIONS |
| 117 |
|
| 118 |
=over 4 |
| 119 |
|
| 120 |
=item B<Recurrences which change years> |
| 121 |
|
| 122 |
It is now valid to have a recurrence defined for New Year's day which |
| 123 |
pushes the holiday to the previous year. |
| 124 |
|
| 125 |
For example, the most useful definition of New Year's day is: |
| 126 |
|
| 127 |
1*1:0:1:0:0:0*DWD = New Year's Day |
| 128 |
|
| 129 |
which means to choose the closest working day to observe the |
| 130 |
holiday, even though this might mean that the holiday is observed |
| 131 |
on the previous year. |
| 132 |
|
| 133 |
=item B<Order of definitions is preserved> |
| 134 |
|
| 135 |
The order of the definitions is preserved. In other words, when looking |
| 136 |
at the holidays for a year, previously defined holidays (in the order |
| 137 |
given in the config file) are correctly handled. |
| 138 |
|
| 139 |
As an example, if you wanted to define both Christmas and Boxing days |
| 140 |
(Boxing is the day after Christmas, and is celebrated in some parts of |
| 141 |
the world), and you wanted to celebrate Christmas on a business day on |
| 142 |
or after Dec 25, and Boxing day as the following work day, you could do |
| 143 |
it in one of the following ways: |
| 144 |
|
| 145 |
1*12:0:25:0:0:0*NWD = Christmas |
| 146 |
1*12:0:26:0:0:0*NWD = Boxing |
| 147 |
|
| 148 |
or |
| 149 |
|
| 150 |
1*12:0:25:0:0:0*NWD = Christmas |
| 151 |
1*12:0:25:0:0:0*NWD = Boxing |
| 152 |
|
| 153 |
Holidays go into affect the minute they are parsed which is why the |
| 154 |
second example works (though for clarity, the first one is |
| 155 |
preferable). The first recurrence defined the first business day on |
| 156 |
or after Dec 25 as Christmas. The second one then defines the |
| 157 |
business day after that as Boxing day. Since the definitions are |
| 158 |
stored as a list (NOT a hash as they were in Date::Manip 5.xx), using |
| 159 |
the same recurrence twice does not cause a problem. |
| 160 |
|
| 161 |
=item B<Multiple holidays> |
| 162 |
|
| 163 |
Having multiple holidays on a single day is allowed. As an example, |
| 164 |
you may want to look at New Years day as both the observed and actual |
| 165 |
holidays, so you might have: |
| 166 |
|
| 167 |
1*1:0:1:0:0:0*DWD = New Year's Day (observed) |
| 168 |
Jan 1 = New Year's Day |
| 169 |
|
| 170 |
Most of the time, both will fall on the same day, but sometimes |
| 171 |
they may differ. In this example, it is important that the |
| 172 |
observed holiday be listed first. Otherwise, Jan 1 will be |
| 173 |
marked as a holiday and then the observed date will check Jan 1, |
| 174 |
but where it is not a business day, it will move to another day |
| 175 |
(due to the DWD modifier). |
| 176 |
|
| 177 |
Likewise, the two holidays: |
| 178 |
|
| 179 |
3rd Sunday in June = Father's Day |
| 180 |
Jun 17 = Bunker Hill Day |
| 181 |
|
| 182 |
sometimes fall on the same day. Using the |
| 183 |
C<Date::Manip::Date::list_holidays> method (or the C<Date_IsHoliday> |
| 184 |
function), you can get a list of all names that the date contains. |
| 185 |
|
| 186 |
=item B<Complex holiday descriptions> |
| 187 |
|
| 188 |
Occasionally, you cannot describe a holiday using a single line. For |
| 189 |
example, the US Federal Reserve banks use a complex holiday description |
| 190 |
where: |
| 191 |
|
| 192 |
For holidays falling on Saturday, Federal Reserve Banks |
| 193 |
and Branches will be open the preceding Friday. For holidays |
| 194 |
falling on Sunday, all Federal Reserve Banks and Branches |
| 195 |
will be closed the following Monday. |
| 196 |
|
| 197 |
Since Saturday is not a business day, the DWD modifier will not work. |
| 198 |
For these, you need a more complicated definition. |
| 199 |
|
| 200 |
The following definitions both work: |
| 201 |
|
| 202 |
# Saturday |
| 203 |
1*1:0:1:0:0:0*NBD,BD1,IBD,FD1 = New Year's Day |
| 204 |
# Sunday (observed Monday) |
| 205 |
1*1:0:1:0:0:0*NBD,BD1,NBD,FD2 = New Year's Day |
| 206 |
# M-F |
| 207 |
1*1:0:1:0:0:0*IBD = New Year's Day |
| 208 |
|
| 209 |
and |
| 210 |
|
| 211 |
# Saturday |
| 212 |
1*1:0:1:0:0:0*IW6 = New Year's Day |
| 213 |
# Sunday (observed Monday) |
| 214 |
1*1:0:1:0:0:0*IW7,FD1 = New Year's Day |
| 215 |
# M-F |
| 216 |
1*1:0:1:0:0:0*IBD = New Year's Day |
| 217 |
|
| 218 |
=back |
| 219 |
|
| 220 |
=head1 EVENTS |
| 221 |
|
| 222 |
The Events section of the config file is similar to the Holiday section. |
| 223 |
It is used to name certain days or times, but there are a few important |
| 224 |
differences: |
| 225 |
|
| 226 |
=over 4 |
| 227 |
|
| 228 |
=item B<Events can be assigned to any time and duration> |
| 229 |
|
| 230 |
All holidays are exactly 1 day long. They are assigned to a period |
| 231 |
of time from midnight to midnight. |
| 232 |
|
| 233 |
Events can be based at any time of the day, and may be of any duration. |
| 234 |
|
| 235 |
=item B<Events don't affect business mode calculations> |
| 236 |
|
| 237 |
Unlike holidays, events are completely ignored when doing business |
| 238 |
mode calculations. |
| 239 |
|
| 240 |
=back |
| 241 |
|
| 242 |
Whereas holidays were added with business mode math in mind, events |
| 243 |
were added with calendar and scheduling applications in mind. |
| 244 |
|
| 245 |
Every line in the events section is of the form: |
| 246 |
|
| 247 |
EVENT = NAME |
| 248 |
|
| 249 |
where NAME is the name of the event, and EVENT defines when it occurs |
| 250 |
and its duration. An EVENT can be defined in the following ways: |
| 251 |
|
| 252 |
Date |
| 253 |
YMD |
| 254 |
YM |
| 255 |
Recur |
| 256 |
|
| 257 |
Date ; Date |
| 258 |
YMD ; YMD |
| 259 |
YM ; YM |
| 260 |
Date ; Delta |
| 261 |
Recur ; Delta |
| 262 |
|
| 263 |
Date refers to a full date/time (and is any string that can be parsed |
| 264 |
by C<Date::Manip::Date::parse>). YMD is any string which can be parsed by |
| 265 |
C<Date::Manip::Date::parse_date>. YM is any string which can be parsed by |
| 266 |
the parse_date method to give a date in the current year. Recur is a |
| 267 |
partial or fully specified recurrence. Delta is any string that can be |
| 268 |
parsed to form a delta. |
| 269 |
|
| 270 |
With the "Date" form, or the "Recur" form, the event starts at the |
| 271 |
time (or times) specified by the date or recurrence, and last 1 hour |
| 272 |
long. With the "YMD" and "YM" forms, the event occurs on the given |
| 273 |
day, and lasts all day. |
| 274 |
|
| 275 |
With all of the two part forms ("Date;Date", "YM;YM", etc.), the event |
| 276 |
starts at the first date and goes to the second date, or goes an |
| 277 |
amount of time specified by the delta. |
| 278 |
|
| 279 |
The "YMD;YMD" and "YM;YM" forms means that the event lasts from the |
| 280 |
start of the first date to the end of the second. In the Date;Date |
| 281 |
form, the event goes from the first date to the second date |
| 282 |
inclusive. In other words, both dates are in the event. In the |
| 283 |
"Date;Delta" and "Recur;Delta" forms, the Delta tells the length of |
| 284 |
the event. Also, in the Date;Date form, the second date may NOT be |
| 285 |
expressed as a delta. |
| 286 |
|
| 287 |
Currently, having an event longer than 1 year is NOT supported, but no |
| 288 |
checking is done for this. |
| 289 |
|
| 290 |
=head1 KNOWN BUGS |
| 291 |
|
| 292 |
None known. |
| 293 |
|
| 294 |
=head1 BUGS AND QUESTIONS |
| 295 |
|
| 296 |
Please refer to the L<Date::Manip::Problems> documentation for |
| 297 |
information on submitting bug reports or questions to the author. |
| 298 |
|
| 299 |
=head1 SEE ALSO |
| 300 |
|
| 301 |
L<Date::Manip> - main module documentation |
| 302 |
|
| 303 |
=head1 LICENSE |
| 304 |
|
| 305 |
This script is free software; you can redistribute it and/or |
| 306 |
modify it under the same terms as Perl itself. |
| 307 |
|
| 308 |
=head1 AUTHOR |
| 309 |
|
| 310 |
Sullivan Beck ([email protected]) |
| 311 |
|
| 312 |
=cut |