Debian Codegraph @

lib/Date/Manip/DM5.pod

raw
1 =pod
2
3 =head1 NAME
4
5 Date::Manip::DM5 - Date manipulation routines
6
7 =head1 SYNOPSIS
8
9 use Date::Manip;
10
11 $version = DateManipVersion;
12
13 Date_Init();
14 Date_Init("VAR=VAL","VAR=VAL",...);
15 @list = Date_Init();
16 @list = Date_Init("VAR=VAL","VAR=VAL",...);
17
18 $date = ParseDate(\@args);
19 $date = ParseDate($string);
20 $date = ParseDate(\$string);
21
22 @date = UnixDate($date,@format);
23 $date = UnixDate($date,@format);
24
25 $delta = ParseDateDelta(\@args);
26 $delta = ParseDateDelta($string);
27 $delta = ParseDateDelta(\$string);
28
29 @str = Delta_Format($delta,$dec,@format);
30 $str = Delta_Format($delta,$dec,@format);
31
32 $recur = ParseRecur($string,$base,$date0,$date1,$flags);
33 @dates = ParseRecur($string,$base,$date0,$date1,$flags);
34
35 $flag = Date_Cmp($date1,$date2);
36
37 $d = DateCalc($d1,$d2 [,$errref] [,$del]);
38
39 $date = Date_SetTime($date,$hr,$min,$sec);
40 $date = Date_SetTime($date,$time);
41
42 $date = Date_SetDateField($date,$field,$val [,$nocheck]);
43
44 $date = Date_GetPrev($date,$dow,$today,$hr,$min,$sec);
45 $date = Date_GetPrev($date,$dow,$today,$time);
46
47 $date = Date_GetNext($date,$dow,$today,$hr,$min,$sec);
48 $date = Date_GetNext($date,$dow,$today,$time);
49
50 $name = Date_IsHoliday($date);
51
52 $listref = Events_List($date);
53 $listref = Events_List($date0,$date1);
54
55 $date = Date_ConvTZ($date);
56 $date = Date_ConvTZ($date,$from);
57 $date = Date_ConvTZ($date,"",$to);
58 $date = Date_ConvTZ($date,$from,$to);
59
60 $flag = Date_IsWorkDay($date [,$flag]);
61
62 $date = Date_NextWorkDay($date,$off [,$flag]);
63
64 $date = Date_PrevWorkDay($date,$off [,$flag]);
65
66 $date = Date_NearestWorkDay($date [,$tomorrowfirst]);
67
68 The above routines all check to make sure that Date_Init is called. If it
69 hasn't been, they will call it automatically. As a result, there is usually
70 no need to call Date_Init explicitly unless you want to change some of the
71 config variables (described below). They also do error checking on the
72 input.
73
74 The routines listed below are intended primarily for internal use by other
75 Date::Manip routines. They do little or no error checking, and do not
76 explicitly call Date_Init. Those functions are all done in the main
77 Date::Manip routines above.
78
79 Because they are significantly faster than the full Date::Manip routines,
80 they are available for use with a few caveats. Since little or no
81 error checking is done, it is the responsibility of the programmer to
82 ensure that valid data (AND valid dates) are passed to them. Passing
83 invalid data (such as a non-numeric month) or invalid dates (Feb 31)
84 will fail in unpredictable ways (possibly returning erroneous results).
85 Also, since Date_Init is not called by these, it must be called
86 explicitly by the programmer before using these routines.
87
88 In the following routines, $y may be entered as either a 2 or 4 digit year
89 (it will be converted to a 4 digit year based on the variable YYtoYYYY
90 described below). Month and day should be numeric in all cases. Most (if
91 not all) of the information below can be gotten from UnixDate which is
92 really the way I intended it to be gotten, but there are reasons to use
93 these (these are significantly faster).
94
95 $day = Date_DayOfWeek($m,$d,$y);
96 $secs = Date_SecsSince1970($m,$d,$y,$h,$mn,$s);
97 $secs = Date_SecsSince1970GMT($m,$d,$y,$h,$mn,$s);
98 $days = Date_DaysSince1BC($m,$d,$y);
99 $day = Date_DayOfYear($m,$d,$y);
100 ($y,$m,$d,$h,$mn,$s) = Date_NthDayOfYear($y,$n);
101 $days = Date_DaysInYear($y);
102 $days = Date_DaysInMonth($m,$y);
103 $wkno = Date_WeekOfYear($m,$d,$y,$first);
104 $flag = Date_LeapYear($y);
105 $day = Date_DaySuffix($d);
106 $tz = Date_TimeZone();
107
108 =head1 ROUTINES
109
110 =over 4
111
112 =item B<Date_Init>
113
114 Date_Init();
115 Date_Init("VAR=VAL","VAR=VAL",...);
116 @list = Date_Init();
117 @list = Date_Init("VAR=VAL","VAR=VAL",...);
118
119 Normally, it is not necessary to explicitly call Date_Init. The first
120 time any of the other routines are called, Date_Init will be called to set
121 everything up. If for some reason you want to change the configuration of
122 Date::Manip, you can pass the appropriate string or strings into Date_Init
123 to reinitialize things.
124
125 The strings to pass in are of the form "VAR=VAL". Any number may be
126 included and they can come in any order. VAR may be any configuration
127 variable. A list of all configuration variables is given in the section
128 CUSTOMIZING DATE::MANIP below. VAL is any allowed value for that variable.
129 For example, to switch from English to French and use non-US format (so
130 that 12/10 is Oct 12), do the following:
131
132 Date_Init("Language=French","DateFormat=non-US");
133
134 If Date_Init is called in list context, it will return a list of all
135 config variables and their values suitable for passing in to Date_Init
136 to return Date::Manip to the current state. The only possible problem is
137 that by default, holidays will not be erased, so you may need to prepend
138 the "EraseHolidays=1" element to the list.
139
140 =item B<ParseDate>
141
142 $date = ParseDate(\@args);
143 $date = ParseDate($string);
144 $date = ParseDate(\$string);
145
146 This takes an array or a string containing a date and parses it. When the
147 date is included as an array (for example, the arguments to a program) the
148 array should contain a valid date in the first one or more elements
149 (elements after a valid date are ignored). Elements containing a valid
150 date are shifted from the array. The largest possible number of elements
151 which can be correctly interpreted as a valid date are always used. If a
152 string is entered rather than an array, that string is tested for a valid
153 date. The string is unmodified, even if passed in by reference.
154
155 The real work is done in the ParseDateString routine.
156
157 The ParseDate routine is primarily used to handle command line arguments.
158 If you have a command where you want to enter a date as a command line
159 argument, you can use Date::Manip to make something like the following
160 work:
161
162 mycommand -date Dec 10 1997 -arg -arg2
163
164 No more reading man pages to find out what date format is required in a
165 man page.
166
167 Historical note: this is originally why the Date::Manip routines were
168 written (though long before they were released as the Date::Manip module).
169 I was using a bunch of programs (primarily batch queue managers) where
170 dates and times were entered as command line options and I was getting
171 highly annoyed at the many different (but not compatible) ways that they
172 had to be entered. Date::Manip originally consisted of basically 1 routine
173 which I could pass "@ARGV" to and have it remove a date from the beginning.
174
175 =item B<ParseDateString>
176
177 $date = ParseDateString($string);
178
179 This routine is called by ParseDate, but it may also be called directly
180 to save some time (a negligible amount).
181
182 NOTE: One of the most frequently asked questions that I have gotten
183 is how to parse seconds since the epoch. ParseDateString cannot simply
184 parse a number as the seconds since the epoch (it conflicts with some
185 ISO-8601 date formats). There are two ways to get this information.
186 First, you can do the following:
187
188 $secs = ... # seconds since Jan 1, 1970 00:00:00 GMT
189 $date = DateCalc("Jan 1, 1970 00:00:00 GMT","+ $secs");
190
191 Second, you can call it directly as:
192
193 $date = ParseDateString("epoch $secs");
194
195 To go backwards, just use the "%s" format of UnixDate:
196
197 $secs = UnixDate($date,"%s");
198
199 A full date actually includes 2 parts: date and time. A time must include
200 hours and minutes and can optionally include seconds, fractional seconds,
201 an am/pm type string, and a time zone. For example:
202
203 [at] HH:MN [Zone]
204 [at] HH:MN [am] [Zone]
205 [at] HH:MN:SS [am] [Zone]
206 [at] HH:MN:SS.SSSS [am] [Zone]
207 [at] HH am [Zone]
208
209 Hours can be written using 1 or 2 digits, but the single digit form may
210 only be used when no ambiguity is introduced (i.e. when it is not
211 immediately preceded by a digit).
212
213 A time is usually entered in 24 hour mode, but 12 hour mode can be used
214 as well if AM/PM are entered (AM can be entered as AM or A.M. or other
215 variations depending on the language).
216
217 Fractional seconds are also supported in parsing but the fractional part is
218 discarded (with NO rounding occurring).
219
220 Time zones always appear immediately after the time. A number of different
221 forms are supported (see the section TIME ZONES below).
222
223 Incidentally, the time is removed from the date before the date is parsed,
224 so the time may appear before or after the date, or between any two parts
225 of the date.
226
227 Valid date formats include the ISO 8601 formats:
228
229 YYYYMMDDHHMNSSF...
230 YYYYMMDDHHMNSS
231 YYYYMMDDHHMN
232 YYYYMMDDHH
233 YY-MMDDHHMNSSF...
234 YY-MMDDHHMNSS
235 YY-MMDDHHMN
236 YY-MMDDHH
237 YYYYMMDD
238 YYYYMM
239 YYYY
240 YY-MMDD
241 YY-MM
242 YY
243 YYYYwWWD ex. 1965-W02-2
244 YYwWWD
245 YYYYDOY ex. 1965-045
246 YYDOY
247
248 In the above list, YYYY and YY signify 4 or 2 digit years, MM, DD, HH, MN, SS
249 refer to two digit month, day, hour, minute, and second respectively. F...
250 refers to fractional seconds (any number of digits) which will be ignored.
251 In all cases, the date and time parts may be separated by the letter "T"
252 (but this is optional), so
253 2002-12-10-12:00:00
254 2002-12-10T12:00:00
255 are identical.
256
257 The last 4 formats can be explained by example: 1965-w02-2 refers to Tuesday
258 (day 2) of the 2nd week of 1965. 1965-045 refers to the 45th day of 1965.
259
260 In all cases, parts of the date may be separated by dashes "-". If this is
261 done, 1 or 2 digit forms of MM, DD, etc. may be used. All dashes are
262 optional except for those given in the table above (which MUST be included
263 for that format to be correctly parsed). So 19980820, 1998-0820,
264 1998-08-20, 1998-8-20, and 199808-20 are all equivalent, but that date may
265 NOT be written as 980820 (it must be written as 98-0820).
266
267 NOTE: Even though not allowed in the standard, the time zone for an ISO-8601
268 date is flexible and may be any of the time zones understood by Date::Manip.
269
270 Additional date formats are available which may or may not be common including:
271
272 MM/DD **
273 MM/DD/YY **
274 MM/DD/YYYY **
275
276 mmmDD DDmmm mmmYYYY/DD mmmYYYY
277 mmmDD/YY DDmmmYY DD/YYmmm YYYYmmmDD YYYYmmm
278 mmmDDYYYY DDmmmYYYY DDYYYYmmm YYYY/DDmmm
279
280 Where mmm refers to the name of a month. All parts of the date can be
281 separated by valid separators (space, "/", or "."). The separator "-" may
282 be used as long as it doesn't conflict with an ISO 8601 format, but this
283 is discouraged since it is easy to overlook conflicts. For example, the
284 format MM/DD/YY is just fine, but MM-DD-YY does not work since it conflicts
285 with YY-MM-DD. To be safe, if "-" is used as a separator in a non-ISO
286 format, they should be turned into "/" before calling the Date::Manip
287 routines. As with ISO 8601 formats, all separators are optional except for
288 those given as a "/" in the list above.
289
290 ** Note that with these formats, Americans tend to write month first, but
291 many other countries tend to write day first. The latter behavior can be
292 obtained by setting the config variable DateFormat to something other than
293 "US" (see CUSTOMIZING DATE::MANIP below).
294
295 Date separators are treated very flexibly (they are converted to spaces),
296 so the following dates are all equivalent:
297
298 12/10/1965
299 12-10 / 1965
300 12 // 10 -. 1965
301
302 In some cases, this may actually be TOO flexible, but no attempt is made to
303 trap this.
304
305 Years can be entered as 2 or 4 digits, days and months as 1 or 2 digits.
306 Both days and months must include 2 digits whenever they are immediately
307 adjacent to another numeric part of the date or time. Date separators
308 are required if single digit forms of DD or MM are used. If separators
309 are not used, the date will either be unparsable or will get parsed
310 incorrectly.
311
312 Miscellaneous other allowed formats are:
313 which dofw in mmm in YY "first Sunday in June
314 1996 at 14:00" **
315 dofw week num YY "Sunday week 22 1995" **
316 which dofw YY "22nd Sunday at noon" **
317 dofw which week YY "Sunday 22nd week in
318 1996" **
319 next/last dofw "next Friday at noon"
320 next/last week/month "next month"
321 in num days/weeks/months "in 3 weeks at 12:00"
322 num days/weeks/months later "3 weeks later"
323 num days/weeks/months ago "3 weeks ago"
324 dofw in num week "Friday in 2 weeks"
325 in num weeks dofw "in 2 weeks on Friday"
326 dofw num week ago "Friday 2 weeks ago"
327 num week ago dofw "2 weeks ago Friday"
328 last day in mmm in YY "last day of October"
329 dofw "Friday" (Friday of
330 current week)
331 Nth "12th", "1st" (day of
332 current month)
333 epoch SECS seconds since the epoch
334 (negative values are
335 supported)
336
337 ** Note that the formats "Sunday week 22" and "22nd Sunday" give very
338 different behaviors. "Sunday week 22" returns the Sunday of the 22nd week
339 of the year based on how week 1 is defined. ISO 8601 defines week one to
340 contain Jan 4, so "Sunday week 1" might be the first or second Sunday of
341 the current year, or the last Sunday of the previous year. "22nd Sunday"
342 gives the actual 22nd time Sunday occurs in a given year, regardless of the
343 definition of a week.
344
345 Note that certain words such as "in", "at", "of", etc. which commonly appear
346 in a date or time are ignored. Also, the year is always optional.
347
348 In addition, the following strings are recognized:
349 today (exactly now OR today at a given time if a time is specified)
350 now (synonym for today)
351 yesterday (exactly 24 hours ago unless a time is specified)
352 tomorrow (exactly 24 hours from now unless a time is specified)
353 noon (12:00:00)
354 midnight (00:00:00)
355 Other languages have similar (and in some cases additional) strings.
356
357 Some things to note:
358
359 All strings are case insensitive. "December" and "DEceMBer" both work.
360
361 When a part of the date is not given, defaults are used: year defaults
362 to current year; hours, minutes, seconds to 00.
363
364 The year may be entered as 2 or 4 digits. If entered as 2 digits, it will
365 be converted to a 4 digit year. There are several ways to do this based on
366 the value of the YYtoYYYY variable (described below). The default behavior
367 it to force the 2 digit year to be in the 100 year period CurrYear-89 to
368 CurrYear+10. So in 1996, the range is [1907 to 2006], and the 2 digit year
369 05 would refer to 2005 but 07 would refer to 1907. See CUSTOMIZING
370 DATE::MANIP below for information on YYtoYYYY for other methods.
371
372 Dates are always checked to make sure they are valid.
373
374 In all of the formats, the day of week ("Friday") can be entered anywhere
375 in the date and it will be checked for accuracy. In other words,
376 "Tue Jul 16 1996 13:17:00"
377 will work but
378 "Jul 16 1996 Wednesday 13:17:00"
379 will not (because Jul 16, 1996 is Tuesday, not Wednesday). Note that
380 depending on where the weekday comes, it may give unexpected results when
381 used in array context (with ParseDate). For example, the date
382 ("Jun","25","Sun","1990") would return June 25 of the current year since
383 Jun 25, 1990 is not Sunday.
384
385 The times "12:00 am", "12:00 pm", and "midnight" are not well defined. For
386 good or bad, I use the following convention in Date::Manip:
387 midnight = 12:00am = 00:00:00
388 noon = 12:00pm = 12:00:00
389 and the day goes from 00:00:00 to 23:59:59. In other words, midnight is the
390 beginning of a day rather than the end of one. The time 24:00:00 is also
391 allowed (though it is automatically transformed to 00:00:00 of the following
392 day).
393
394 The format of the date returned is YYYYMMDDHH:MM:SS. The advantage of this
395 time format is that two times can be compared using simple string comparisons
396 to find out which is later. Also, it is readily understood by a human.
397 Alternate forms can be used if that is more convenient. See Date_Init below
398 and the config variable Internal.
399
400 NOTE: The format for the date is going to change at some point in the future
401 to YYYYMMDDHH:MN:SS+HHMN*FLAGS. In order to maintain compatibility, you
402 should use UnixDate to extract information from a date, and Date_Cmp to compare
403 two dates. The simple string comparison will only work for dates in the same
404 time zone.
405
406 =item B<UnixDate>
407
408 @date = UnixDate($date,@format);
409 $date = UnixDate($date,@format);
410
411 This takes a date and a list of strings containing formats roughly
412 identical to the format strings used by the UNIX date(1) command. Each
413 format is parsed and an array of strings corresponding to each format is
414 returned.
415
416 $date may be any string that can be parsed by ParseDateString.
417
418 The format options are:
419
420 Year
421 %y year - 00 to 99
422 %Y year - 0001 to 9999
423 Month, Week
424 %m month of year - 01 to 12
425 %f month of year - " 1" to "12"
426 %b,%h month abbreviation - Jan to Dec
427 %B month name - January to December
428 Day
429 %j day of the year - 001 to 366
430 %d day of month - 01 to 31
431
432 %e day of month - " 1" to "31"
433 %v weekday abbreviation - " S"," M"," T"," W","Th"," F","Sa"
434 %a weekday abbreviation - Sun to Sat
435 %A weekday name - Sunday to Saturday
436 %w day of week - 1 (Monday) to 7 (Sunday)
437 %E day of month with suffix - 1st, 2nd, 3rd...
438 Hour
439 %H hour - 00 to 23
440 %k hour - " 0" to "23"
441 %i hour - " 1" to "12"
442 %I hour - 01 to 12
443 %p AM or PM
444 Minute, Second, Time zone
445 %M minute - 00 to 59
446 %S second - 00 to 59
447 %Z time zone - "EDT"
448 %z time zone as GMT offset - "+0100"
449 Epoch (see NOTE 3 below)
450 %s seconds from 1/1/1970 GMT- negative if before 1/1/1970
451 %o seconds from Jan 1, 1970
452 in the current time zone
453 Date, Time
454 %c %a %b %e %H:%M:%S %Y - Fri Apr 28 17:23:15 1995
455 %C,%u %a %b %e %H:%M:%S %z %Y - Fri Apr 28 17:25:57 EDT 1995
456 %g %a, %d %b %Y %H:%M:%S %z - Fri, 28 Apr 1995 17:23:15 EDT
457 %D %m/%d/%y - 04/28/95
458 %x %m/%d/%y or %d/%m/%y - 04/28/95 or 28/04/28
459 (Depends on DateFormat variable)
460 %l date in ls(1) format (see NOTE 1 below)
461 %b %e $H:$M - Apr 28 17:23 (if within 6 months)
462 %b %e %Y - Apr 28 1993 (otherwise)
463 %r %I:%M:%S %p - 05:39:55 PM
464 %R %H:%M - 17:40
465 %T,%X %H:%M:%S - 17:40:58
466 %V %m%d%H%M%y - 0428174095
467 %Q %Y%m%d - 19961025
468 %q %Y%m%d%H%M%S - 19961025174058
469 %P %Y%m%d%H%M%S - 1996102517:40:58
470 %O %Y-%m-%dT%H:%M:%S - 1996-10-25T17:40:58
471 %F %A, %B %e, %Y - Sunday, January 1, 1996
472 %K %Y-%j - 1997-045
473 Special Year/Week formats (see NOTE 2 below)
474 %G year, Monday as first
475 day of week - 0001 to 9999
476 %W week of year, Monday
477 as first day of week - 01 to 53
478 %L year, Sunday as first
479 day of week - 0001 to 9999
480 %U week of year, Sunday
481 as first day of week - 01 to 53
482 %J %G-W%W-%w - 1997-W02-2
483 Other formats
484 %n insert a newline character
485 %t insert a tab character
486 %% insert a `%' character
487 %+ insert a `+' character
488 The following formats are currently unused but may be used in the future:
489 N 1234567890 !@#$^&*()_|-=\`[];',./~{}:<>?
490 They currently insert the character following the %, but may (and probably
491 will) change in the future as new formats are added.
492
493 If a lone percent is the final character in a format, it is ignored.
494
495 The formats used in this routine were originally based on date.pl (version
496 3.2) by Terry McGonigal, as well as a couple taken from different versions
497 of the Solaris date(1) command. Also, several have been added which are
498 unique to Date::Manip.
499
500 NOTE 1:
501
502 The ls format (%l) applies to date within the past OR future 6 months!
503
504 NOTE 2:
505
506 The %U, %W, %L, %G, and %J formats are used to support the ISO-8601 format:
507 YYYY-wWW-D. In this format, a date is written as a year, the week of the
508 year, and the day of the week. Technically, the week may be considered to
509 start on any day of the week, but Sunday and Monday are the both common
510 choices, so both are supported.
511
512 The %W and %G formats return the week-of-year and the year treating weeks
513 as starting on Monday.
514
515 The %U and %L formats return the week-of-year and the year treating weeks
516 as starting on Sunday.
517
518 Most of the time, the %L and %G formats returns the same value as the %Y
519 format, but there is a problem with days occurring in the first or last week
520 of the year.
521
522 The ISO-8601 representation of Jan 1, 1993 written in the YYYY-wWW-D format
523 is actually 1992-W53-5. In other words, Jan 1 is treated as being in the
524 last week of the preceding year. Depending on the year, days in the first
525 week of a year may belong to the previous year, and days in the final week
526 of a year may belong to the next year. The week is assigned to the year
527 which has most of the days. For example, if the week starts on Sunday,
528 then the last week of 2003 is 2003-12-28 to 2004-01-03. This week is
529 assigned to 2003 since 4 of the days in it are in 2003 and only 3 of them
530 are in 2004. The first week of 2004 starts on 2004-01-04.
531
532 The %U and %W formats return a week-of-year number from 01 to 53. %L and
533 %G return the corresponding year, and to get this type of information,
534 you should always use the (%W,%G) combination or (%U,%L) combination. %Y
535 should not be used as it will yield incorrect results.
536
537 %J returns the full ISO-8601 format (%G-W%W-%w).
538
539 NOTE 3:
540
541 The %s and %o formats return negative values if the date is before
542 the start of the epoch. Other Unix utilities would return an error, or
543 a zero, so if you are going to use Date::Manip in conjunction with these,
544 be sure to check for a negative value.
545
546 =item B<ParseDateDelta>
547
548 $delta = ParseDateDelta(\@args);
549 $delta = ParseDateDelta($string);
550 $delta = ParseDateDelta(\$string);
551
552 This takes an array and shifts a valid delta date (an amount of time)
553 from the array. Recognized deltas are of the form:
554 +Yy +Mm +Ww +Dd +Hh +MNmn +Ss
555 examples:
556 +4 hours +3mn -2second
557 + 4 hr 3 minutes -2
558 4 hour + 3 min -2 s
559 +Y:+M:+W:+D:+H:+MN:+S
560 examples:
561 0:0:0:0:4:3:-2
562 +4:3:-2
563 mixed format
564 examples:
565 4 hour 3:-2
566
567 A field in the format +Yy is a sign, a number, and a string specifying
568 the type of field. The sign is "+", "-", or absent (defaults to the
569 next larger element). The valid strings specifying the field type
570 are:
571 y: y, yr, year, years
572 m: m, mon, month, months
573 w: w, wk, ws, wks, week, weeks
574 d: d, day, days
575 h: h, hr, hour, hours
576 mn: mn, min, minute, minutes
577 s: s, sec, second, seconds
578
579 Also, the "s" string may be omitted. The sign, number, and string may
580 all be separated from each other by any number of whitespace.
581
582 In the date, all fields must be given in the order: Y M W D H MN S. Any
583 number of them may be omitted provided the rest remain in the correct
584 order. In the 2nd (colon) format, from 2 to 7 of the fields may be given.
585 For example +D:+H:+MN:+S may be given to specify only four of the fields.
586 In any case, both the MN and S field may be present. No spaces may be
587 present in the colon format.
588
589 Deltas may also be given as a combination of the two formats. For example,
590 the following is valid: +Yy +D:+H:+MN:+S. Again, all fields must be given
591 in the correct order.
592
593 The word "in" may be given (prepended in English) to the delta ("in 5 years")
594 and the word "ago" may be given (appended in English) ("6 months ago"). The
595 "in" is completely ignored. The "ago" has the affect of reversing all signs
596 that appear in front of the components of the delta. I.e. "-12 yr 6 mon ago"
597 is identical to "+12yr +6mon" (don't forget that there is an implied minus
598 sign in front of the 6 because when no sign is explicitly given, it carries
599 the previously entered sign).
600
601 One thing is worth noting. The year/month and day/hour/min/sec parts are
602 returned in a "normalized" form. That is, the signs are adjusted so as to
603 be all positive or all negative. For example, "+ 2 day - 2hour" does not
604 return "0:0:0:2:-2:0:0". It returns "+0:0:0:1:22:0:0" (1 day 22 hours
605 which is equivalent). I find (and I think most others agree) that this is
606 a more useful form.
607
608 Since the year/month and day/hour/min/sec parts must be normalized
609 separately there is the possibility that the sign of the two parts will be
610 different. So, the delta "+ 2years -10 months - 2 days + 2 hours" produces
611 the delta "+1:2:-0:1:22:0:0".
612
613 It is possible to include a sign for all elements that is output. See the
614 configuration variable DeltaSigns below.
615
616 NOTE: The internal format of the delta changed in version 5.30 from
617 Y:M:D:H:MN:S to Y:M:W:D:H:MN:S . Also, it is going to change again at some
618 point in the future to Y:M:W:D:H:MN:S*FLAGS . Use the routine Delta_Format
619 to extract information rather than parsing it yourself.
620
621 =item B<Delta_Format>
622
623 @str = Delta_Format($delta [,$mode], $dec,@format);
624 $str = Delta_Format($delta [,$mode], $dec,@format);
625
626 This is similar to the UnixDate routine except that it extracts information
627 from a delta. Unlike the UnixDate routine, most of the formats are 2
628 characters instead of 1.
629
630 Formats currently understood are:
631
632 %Xv : the value of the field named X
633 %Xd : the value of the field X, and all smaller fields, expressed in
634 units of X
635 %Xh : the value of field X, and all larger fields, expressed in units
636 of X
637 %Xt : the value of all fields expressed in units of X
638
639 X is one of y,M,w,d,h,m,s (case sensitive).
640
641 %% : returns a "%"
642
643 So, the format "%hd" means the values of H, MN, and S expressed in hours.
644 So for the delta "0:0:0:0:2:30:0", this format returns 2.5.
645
646 Delta_Format can operate in two modes: exact and approximate. The exact
647 mode is done by default. Approximate mode can be done by passing in
648 the string "approx" as the 2nd argument.
649
650 In exact mode, Delta_Format only understands "exact" relationships. This
651 means that there can be no mixing of the Y/M and W/D/H/MN/S segments
652 because the relationship because, depending on when the delta occurs, there
653 is no exact relation between the number of years or months and the number
654 of days.
655
656 The two sections are treated completely separate from each other. So,
657 the delta "1:6:1:2:12:0:0" would return the following values:
658
659 %yt = 1.5 (1 year, 6 months)
660 %Mt = 18
661
662 %dt = 9.5 (1 week, 2 days, 12 hours)
663
664 In approximate mode, the relationship of 1 year = 365.25 days is applied
665 (with 1 month equal to 1/12 of a year exactly). So the delta
666 "1:6:1:2:12:0:0" would return the following values:
667
668 %dt = 557.375 (1.5 years of 365.25 days + 9.5 days)
669
670 If $dec is non-zero, the %Xd and %Xt values are formatted to contain $dec
671 decimal places.
672
673 =item B<ParseRecur>
674
675 $recur = ParseRecur($string [,$base,$date0,$date1,$flags]);
676 @dates = ParseRecur($string [,$base,$date0,$date1,$flags]);
677
678 A recurrence refers to a recurring event, and more specifically, an event
679 which occurs on a regular basis. A fully specified recurring event
680 may requires up to four pieces of information.
681
682 First, it requires a description of the frequency of the event. Examples
683 include "the first of every month", "every other day", "the 4th
684 Thursday of each month at 2:00 PM", and "every 2 hours and 30 minutes".
685
686 Second, it may require a base date to work from. This piece of information
687 is not required for every type of recurrence. For example, if the
688 frequency is "the first of every month", no base date is required. All the
689 information about when the event occurs is included in the frequency
690 description. If the frequency were "every other day" though, you need to
691 know at least one day on which the event occurred.
692
693 Third, the recurring event may have a range (a starting and ending date).
694
695 Fourth, there may be some flags included which modify the behavior of the
696 above information.
697
698 The fully specified recurrence is written as these 5 pieces of information
699 (both a start and end date) as an asterisk separated list:
700
701 freq*flags*base*date0*date1
702
703 Here, base, date0, and date1 are any strings (which must not contain any
704 asterisks) which can be parsed by ParseDate. flags is a comma separated
705 list of flags (described below), and freq is a string describing the
706 frequency of the recurring event.
707
708 The syntax of the frequency description is a colon separated list of the
709 format Y:M:W:D:H:MN:S (which stand for year, month, week, etc.). One (and
710 only one) of the colons may optionally be replaced by an asterisk, or an
711 asterisk may be prepended to the string. For example, the following are
712 all valid frequency descriptions:
713
714 1:2:3:4:5:6:7
715 1:2*3:4:5:6:7
716 *1:2:3:4:5:6:7
717
718 But the following are NOT valid because they contain 2 or more asterisks:
719
720 1:2*3:4:5*6:7
721 1*2*3:4:5*6:7
722 *1:2:3:4:5:6*7
723
724 If an asterisk is included, values to the left of it refer to the number of
725 times that time interval occurs between recurring events. For example,
726 if the first part of the recurrence is:
727
728 1:2*
729
730 this says that the recurring event occurs approximately every 1 year and 2
731 months. I say approximately, because elements to the right of the asterisk,
732 as well as any flags included in the recurrence will affect when the actual
733 events occur.
734
735 If no asterisks are included, then the entire recurrence is of this form.
736 For example,
737
738 0:0:0:1:12:0:0
739
740 refers to an event that occurs every 1 day, 12 hours.
741
742 Values that occur after an asterisk refer to a specific value for that type
743 of time element (i.e. exactly as it would appear on a calendar or a clock).
744 For example, if the recurrence ends with:
745
746 *12:0:0
747
748 then the recurring event occurs at 12:00:00 (noon).
749
750 For example:
751
752 0:0:2:1:0:0:0 every 2 weeks and 1 day
753 0:0:0:0:5:30:0 every 5 hours and 30 minutes
754 0:0:0:2*12:30:0 every 2 days at 12:30 (each day)
755
756 Values to the right of the asterisk can be listed a single values, ranges
757 (2 numbers separated by a dash "-"), or a comma separated list of values
758 or ranges. In most cases, negative values are appropriate for the week
759 or day values. -1 stands for the last possible value, -2 for the second
760 to the last, etc.
761
762 Some examples are:
763
764 0:0:0:1*2,4,6:0:0 every day at at 2:00, 4:00, and 6:00
765 0:0:0:2*12-13:0,30:0 every other day at 12:00, 12:30, 13:00,
766 and 13:30
767 0:1:0*-1:0:0:0 the last day of every month
768 *1990-1995:12:0:1:0:0:0
769 Dec 1 in 1990 through 1995
770
771 There is no way to express the following with a single recurrence:
772
773 every day at 12:30 and 1:00
774
775 You have to use two recurrences to do this.
776
777 When a non-zero day element occurs to the right of the asterisk, it can take
778 on multiple meanings, depending on the value of the month and week
779 elements. It can refer to the day of the week, day of the month, or day of
780 the year. Similarly, if a non-zero week element occurs to the right of
781 the asterisk, it actually refers to the nth time a certain day of the week
782 occurs, either in the month or in the year.
783
784 If the week element is non-zero and the day element is non-zero (and to the
785 right of the asterisk), the day element refers to the day of the week. It
786 can be any value from 1 to 7 (negative values -1 to -7 are also
787 allowed). If you use the ISO 8601 convention, the first day of the week is
788 Monday (though Date::Manip can use any day as the start of the week by
789 setting the FirstDay config variable). So, assuming that you are using the
790 ISO 8601 convention, the following examples illustrate day-of-week
791 recurrences:
792
793 0:1*4:2:0:0:0 4th Tuesday (day 2) of every month
794 0:1*-1:2:0:0:0 last Tuesday of every month
795 0:0:3*2:0:0:0 every 3rd Tuesday (every 3 weeks
796 on 2nd day of week)
797 1:0*12:2:0:0:0 the 12th Tuesday of each year
798
799 If the week element is non-zero, and the day element is zero, the day
800 defaults to 1 (i.e. the first day of the week).
801
802 0:1*2:0:0:0:0 the 2nd occurrence of FirstDay
803 in the year (typically Monday)
804 0:1*2:1:0:0:0 the same
805
806 If the week element is zero and the month element is non-zero, the day
807 value is the day of the month (it can be from 1 to 31 or -1 to -31 counting
808 from the end of the month). If a value of 0 is given, it defaults to 1.
809
810 3*1:0:2:12:0:0 every 3 years on Jan 2 at noon
811 0:1*0:2:12,14:0:0 2nd of every month at 12:00 and 14:00
812 0:1:0*-2:0:0:0 2nd to last day of every month
813
814 If the day given refers to the 29th, 30th, or 31st, in a month
815 that does not have that number of days, it is ignored. For example,
816 if you ask for the 31st of every month, it will return dates in Jan,
817 Mar, May, Jul, etc. Months with fewer than 31 days will be ignored.
818
819 If both the month and week elements are zero, and the year element
820 is non-zero, the day value is the day of the year (1 to 365 or 366 -- or
821 the negative numbers to count backwards from the end of the year).
822
823 1:0:0*45:0:0:0 45th day of every year
824
825 Specifying a day that doesn't occur in that year silently ignores that
826 year. The only result of this is that specifying +366 or -366 will ignore
827 all years except leap years.
828
829 I realize that this looks a bit cryptic, but after a discussion on the
830 CALENDAR mailing list, it appeared like there was no concise, flexible
831 notation for handling recurring events. ISO 8601 notations were very bulky
832 and lacked the flexibility I wanted. As a result, I developed this
833 notation (based on crontab formats, but with much more flexibility) which
834 fits in well with this module. Even better, it is able to express every
835 type of recurring event I could think of that is used in common life in
836 (what I believe to be) a very concise and elegant way.
837
838 If ParseRecur is called in scalar context, it returns a string containing a
839 fully specified recurrence (or as much of it as can be determined with
840 unspecified fields left blank). In list context, it returns a list of all
841 dates referred to by a recurrence if enough information is given in the
842 recurrence. All dates returned are in the range:
843
844 date0 <= date < date1
845
846 The argument $string can contain any of the parts of a full recurrence.
847 For example:
848
849 freq
850 freq*flags
851 freq**base*date0*date1
852
853 The only part which is required is the frequency description. Any values
854 contained in $string are overridden or modified by values passed in as
855 parameters to ParseRecur.
856
857 NOTE: If a recurrence has a date0 and date1 in it AND a date0 and date1
858 are passed in to the function, both sets of criteria apply. If flags are
859 passed in, they override any flags in the recurrence UNLESS the flags
860 passed in start with a plus (+) character in which case they are appended
861 to the flags in the recurrence.
862
863 NOTE: Base dates are only used with some types of recurrences. For example,
864
865 0:0:3*2:0:0:0 every 3rd Tuesday
866
867 requires a base date. If a base date is specified which doesn't match the
868 criteria (for example, if a base date falling on Monday were passed in with
869 this recurrence), the base date is moved forward to the first relevant date.
870
871 Other dates do not require a base date. For example:
872
873 0:0*3:2:0:0:0 third Tuesday of every month
874
875 A recurrence written in the above format does NOT provide default values
876 for base, date0, or date1. They must be specified in order to get a list
877 of dates.
878
879 A base date is not used entirely. It is only used to provide the parts
880 necessary for the left part of a recurrence. For example, the recurrence:
881
882 1:3*0:4:0:0:0 every 1 year, 3 months on the 4th day of the month
883
884 would only use the year and month of the base date.
885
886 There are a small handful of English strings which can be parsed in place
887 of a numerical recur description. These include:
888
889 every 2nd day [in 1997]
890 every 2nd day in June [1997]
891 2nd day of every month [in 1997]
892 2nd Tuesday of every month [in 1997]
893 last Tuesday of every month [in 1997]
894 every Tuesday [in 1997]
895 every 2nd Tuesday [in 1997]
896 every 2nd Tuesday in June [1997]
897
898 Each of these set base, date0, and date1 to a default value (the current
899 year with Jan 1 being the base date is the default if the year and month
900 are missing).
901
902 The following flags (case insensitive) are understood:
903
904 PDn : n is 1-7. Means the previous day n not counting today
905 PTn : n is 1-7. Means the previous day n counting today
906 NDn : n is 1-7. Means the next day n not counting today
907 NTn : n is 1-7. Means the next day n counting today
908
909 FDn : n is any number. Means step forward n days.
910 BDn : n is any number. Means step backward n days.
911 FWn : n is any number. Means step forward n workdays.
912 BWn : n is any number. Means step backward n workdays.
913
914 CWD : the closest work day (using the TomorrowFirst config variable).
915 CWN : the closest work day (looking forward first).
916 CWP : the closest work day (looking backward first).
917
918 NWD : next work day counting today
919 PWD : previous work day counting today
920 DWD : next/previous work day (TomorrowFirst config) counting today
921
922 EASTER: select easter for this year (the M, W, D fields are ignored
923 in the recur).
924
925 CWD, CWN, and CWP will usually return the same value, but if you are
926 starting at the middle day of a 3-day weekend (for example), it will return
927 either the first work day of the following week, or the last work day of
928 the previous week depending on whether it looks forward or backward first.
929
930 All flags are applied AFTER the recurrence dates are calculated, and they
931 may move a date outside of the date0 to date1 range. No check is made for
932 this.
933
934 The workday flags do not act exactly the same as a business mode calculation.
935 For example, a date that is Saturday with a FW1 steps forward to the first
936 workday (i.e. Monday).
937
938 =item B<Date_Cmp>
939
940 $flag = Date_Cmp($date1,$date2);
941
942 This takes two dates and compares them. Almost all dates can be compared
943 using the Perl "cmp" command. The only time this will not work is when
944 comparing dates in different time zones. This routine will take that into
945 account.
946
947 NOTE: This routine currently does little more than use "cmp", but once
948 the internal format for storing dates is in place (where time zone information
949 is kept as part of the date), this routine will become more important. You
950 should use this routine in preparation for that version.
951
952 =item B<DateCalc>
953
954 $d = DateCalc($d1,$d2 [,\$err] [,$mode]);
955
956 This takes two dates, deltas, or one of each and performs the appropriate
957 calculation with them. Dates must be a string that can be parsed by
958 ParseDateString. Deltas must be a string that can be parsed by
959 ParseDateDelta. Two deltas add together to form a third delta. A date
960 and a delta returns a 2nd date. Two dates return a delta (the difference
961 between the two dates).
962
963 Since the two items can be interpreted as either dates or deltas, and since
964 many types of dates can be interpreted as deltas (and vice versa), it is
965 a good idea to pass the input through ParseDate or ParseDateDelta as
966 appropriate. For example, the string "09:00:00" can be interpreted either
967 as a date (today at 9:00:00) or a delta (9 hours). To avoid unexpected
968 results, avoid calling DateCalc as:
969
970 $d = DateCalc("09:00:00",$someothervalue);
971
972 Instead, call it as:
973
974 $d = DateCalc(ParseDate("09:00:00"),$someothervalue);
975
976 to force it to be a date, or:
977
978 $d = DateCalc(ParseDateDelta("09:00:00"),$someothervalue);
979
980 to force it to be a delta. This will avoid unexpected results.
981
982 Note that in many cases, it is somewhat ambiguous what the delta
983 actually refers to. Although it is ALWAYS known how many months in a
984 year, hours in a day, etc., it is NOT known (in the generals case) how
985 many days are in a month. As a result, the part of the delta
986 containing month/year and the part with sec/min/hr/day must be treated
987 separately. For example, "Mar 31, 12:00:00" plus a delta of 1month
988 2days would yield "May 2 12:00:00". The year/month is first handled
989 while keeping the same date. Mar 31 plus one month is Apr 31 (but
990 since Apr only has 30 days, it becomes Apr 30). Apr 30 + 2 days is
991 May 2. As a result, in the case where two dates are entered, the
992 resulting delta can take on two different forms. By default
993 ($mode=0), an absolutely correct delta (ignoring daylight saving time)
994 is returned in weeks, days, hours, minutes, and seconds.
995
996 If $mode is 1, the math is done using an approximate mode where a delta is
997 returned using years and months as well. The year and month part is
998 calculated first followed by the rest. For example, the two dates "Mar 12
999 1995" and "Apr 13 1995" would have an exact delta of "31 days" but in the
1000 approximate mode, it would be returned as "1 month 1 day". Also, "Mar 31"
1001 and "Apr 30" would have deltas of "30 days" or "1 month" (since Apr 31
1002 doesn't exist, it drops down to Apr 30). Approximate mode is a more human
1003 way of looking at things (you'd say 1 month and 2 days more often then 33
1004 days), but it is less meaningful in terms of absolute time. In approximate
1005 mode $d1 and $d2 must be dates. If either or both is a delta, the
1006 calculation is done in exact mode.
1007
1008 If $mode is 2, a business mode is used. That is, the calculation is done
1009 using business days, ignoring holidays, weekends, etc. In order to
1010 correctly use this mode, a config file must exist which contains the
1011 section defining holidays (see documentation on the config file below).
1012 The config file can also define the work week and the hours of the work
1013 day, so it is possible to have different config files for different
1014 businesses.
1015
1016 For example, if a config file defines the workday as 08:00 to 18:00, a
1017 work week consisting of Mon-Sat, and the standard (American) holidays, then
1018 from Tuesday at 12:00 to the following Monday at 14:00 is 5 days and 2
1019 hours. If the "end" of the day is reached in a calculation, it
1020 automatically switches to the next day. So, Tuesday at 12:00 plus 6 hours
1021 is Wednesday at 08:00 (provided Wed is not a holiday). Also, a date that
1022 is not during a workday automatically becomes the start of the next
1023 workday. So, Sunday 12:00 and Monday at 03:00 both automatically becomes
1024 Monday at 08:00 (provided Monday is not a holiday). In business mode, any
1025 combination of date and delta may be entered, but a delta should not
1026 contain a year or month field (weeks are fine though).
1027
1028 See Date::Manip::Calc for some additional comments about business mode calculations.
1029
1030 Note that a business week is treated the same as an exact week (i.e. from
1031 Tuesday to Tuesday, regardless of holidays). Because this means that the
1032 relationship between days and weeks is NOT unambiguous, when a delta is
1033 produced from two dates, it will be in terms of d/h/mn/s (i.e. no week
1034 field).
1035
1036 If $mode is 3 (which only applies when two dates are passed in), an exact
1037 business mode is used. In this case, it returns a delta as an exact number
1038 of business days/hours/etc. between the two. Weeks, months, and years are
1039 ignored.
1040
1041 Any other non-nil value of $mode is treated as $mode=1 (approximate mode).
1042
1043 The mode can be automatically set in the dates/deltas passed by including a
1044 key word somewhere in it. For example, in English, if the word
1045 "approximately" is found in either of the date/delta arguments, approximate
1046 mode is forced. Likewise, if the word "business" or "exactly" appears,
1047 business/exact mode is forced (and $mode is ignored). So, the two
1048 following are equivalent:
1049
1050 $date = DateCalc("today","+ 2 business days",\$err);
1051 $date = DateCalc("today","+ 2 days",\$err,2);
1052
1053 Note that if the keyword method is used instead of passing in $mode, it is
1054 important that the keyword actually appear in the argument passed in to
1055 DateCalc. The following will NOT work:
1056
1057 $delta = ParseDateDelta("+ 2 business days");
1058 $today = ParseDate("today");
1059 $date = DateCalc($today,$delta,\$err);
1060
1061 because the mode keyword is removed from a date/delta by the parse routines,
1062 and the mode is reset each time a parse routine is called. Since DateCalc
1063 parses both of its arguments, whatever mode was previously set is ignored.
1064
1065 If \$err is passed in, it is set to:
1066 1 is returned if $d1 is not a delta or date
1067 2 is returned if $d2 is not a delta or date
1068 3 is returned if the date is outside the years 1000 to 9999
1069 This argument is optional, but if included, it must come before $mode.
1070
1071 Nothing is returned if an error occurs.
1072
1073 When a delta is returned, the signs such that it is strictly positive or
1074 strictly negative ("1 day - 2 hours" would never be returned for example).
1075 The only time when this cannot be enforced is when two deltas with a
1076 year/month component are entered. In this case, only the signs on the
1077 day/hour/min/sec part are standardized.
1078
1079 =item B<Date_SetTime>
1080
1081 $date = Date_SetTime($date,$hr,$min,$sec);
1082 $date = Date_SetTime($date,$time);
1083
1084 This takes a date (any string that may be parsed by ParseDateString) and
1085 sets the time in that date. For example, one way to get the time for 7:30
1086 tomorrow would be to use the lines:
1087
1088 $date = ParseDate("tomorrow");
1089 $date = Date_SetTime($date,"7:30");
1090
1091 Note that in this routine (as well as the other routines below which use
1092 a time argument), no real parsing is done on the times. As a result,
1093
1094 $date = Date_SetTime($date,"13:30");
1095
1096 works, but
1097
1098 $date = Date_SetTime($date,"1:30 PM");
1099
1100 doesn't.
1101
1102 =item B<Date_SetDateField>
1103
1104 $date = Date_SetDateField($date,$field,$val [,$nocheck]);
1105
1106 This takes a date and sets one of its fields to a new value. $field is
1107 any of the strings "y", "m", "d", "h", "mn", "s" (case insensitive) and
1108 $val is the new value.
1109
1110 If $nocheck is non-zero, no check is made as to the validity of the date.
1111
1112 =item B<Date_GetPrev>
1113
1114 $date = Date_GetPrev($date,$dow, $curr [,$hr,$min,$sec]);
1115 $date = Date_GetPrev($date,$dow, $curr [,$time]);
1116 $date = Date_GetPrev($date,undef,$curr,$hr,$min,$sec);
1117 $date = Date_GetPrev($date,undef,$curr,$time);
1118
1119 This takes a date (any string that may be parsed by ParseDateString) and finds
1120 the previous occurrence of either a day of the week, or a certain time of day.
1121
1122 If $dow is defined, the previous occurrence of the day of week is returned.
1123 $dow may either be a string (such as "Fri" or "Friday") or a number
1124 (between 1 and 7). The date of the previous $dow is returned.
1125
1126 If $date falls on the day of week given by $dow, the date returned depends
1127 on $curr. If $curr is 0, the date returned is a week before $date. If
1128 $curr is 1, the date returned is the same as $date. If $curr is 2, the date
1129 returned (including the time information) is required to be before $date.
1130
1131 If a time is passed in (either as separate hours, minutes, seconds or as a
1132 time in HH:MM:SS or HH:MM format), the time on this date is set to it. The
1133 following examples should illustrate the use of Date_GetPrev:
1134
1135 date dow curr time returns
1136 Fri Nov 22 18:15:00 Thu any 12:30 Thu Nov 21 12:30:00
1137 Fri Nov 22 18:15:00 Fri 0 12:30 Fri Nov 15 12:30:00
1138 Fri Nov 22 18:15:00 Fri 1/2 12:30 Fri Nov 22 12:30:00
1139
1140 Fri Nov 22 18:15:00 Fri 1 18:30 Fri Nov 22 18:30:00
1141 Fri Nov 22 18:15:00 Fri 2 18:30 Fri Nov 15 18:30:00
1142
1143 If $dow is undefined, then a time must be entered, and the date returned is
1144 the previous occurrence of this time. If $curr is non-zero, the current
1145 time is returned if it matches the criteria passed in. In other words, the
1146 time returned is the last time that a digital clock (in 24 hour mode) would
1147 have displayed the time you passed in. If you define hours, minutes and
1148 seconds default to 0 and you might jump back as much as an entire day. If
1149 hours are undefined, you are looking for the last time the minutes/seconds
1150 appeared on the digital clock, so at most, the time will jump back one hour.
1151
1152 date curr hr min sec returns
1153 Nov 22 18:15:00 0/1 18 undef undef Nov 22 18:00:00
1154 Nov 22 18:15:00 0/1 18 30 0 Nov 21 18:30:00
1155 Nov 22 18:15:00 0 18 15 undef Nov 21 18:15:00
1156 Nov 22 18:15:00 1 18 15 undef Nov 22 18:15:00
1157 Nov 22 18:15:00 0 undef 15 undef Nov 22 17:15:00
1158 Nov 22 18:15:00 1 undef 15 undef Nov 22 18:15:00
1159
1160 =item B<Date_GetNext>
1161
1162 $date = Date_GetNext($date,$dow, $curr [,$hr,$min,$sec]);
1163 $date = Date_GetNext($date,$dow, $curr [,$time]);
1164 $date = Date_GetNext($date,undef,$curr,$hr,$min,$sec);
1165 $date = Date_GetNext($date,undef,$curr,$time);
1166
1167 Similar to Date_GetPrev.
1168
1169 =item B<Date_IsHoliday>
1170
1171 $name = Date_IsHoliday($date);
1172
1173 This returns undef if $date is not a holiday, or a string containing the
1174 name of the holiday otherwise. An empty string is returned for an unnamed
1175 holiday.
1176
1177 =item B<Events_List>
1178
1179 $ref = Events_List($date);
1180 $ref = Events_List($date ,0 [,$flag]);
1181 $ref = Events_List($date0,$date1 [,$flag]);
1182
1183 This returns a list of events. Events are defined in the Events section
1184 of the config file (discussed below).
1185
1186 In the first form (a single argument), $date is any string containing a
1187 date. A list of events active at that precise time will be returned.
1188 The format is similar to when $flag=0, except only a single time will
1189 be returned.
1190
1191 In all other cases, a range of times will be used. If the 2nd argument
1192 evaluates to 0, the range of times will be the 24 hour period from
1193 midnight to midnight containing $date. Otherwise, the range is given
1194 by the two dates.
1195
1196 The value of $flag determines the format of the information that is
1197 returned.
1198
1199 With $flag=0, the events are returned as a reference to a list of the form:
1200
1201 [ date, [ list_of_events ], date, [ list_of_events ], ... ]
1202
1203 For example, if the following events are defined (using the syntax
1204 discussed below in the description of the Event section of the config
1205 file):
1206
1207 2000-01-01 ; 2000-03-21 = Winter
1208 2000-03-22 ; 2000-06-21 = Spring
1209 2000-02-01 = Event1
1210 2000-05-01 = Event2
1211 2000-04-01-12:00:00 = Event3
1212
1213 might result in the following output:
1214
1215 Events_List("2000-04-01")
1216 => [ 2000040100:00:00, [ Spring ] ]
1217
1218 Events_List("2000-04-01 12:30");
1219 => [ 2000040112:30:00, [ Spring, Event3 ] ]
1220
1221 Events_List("2000-04-01",0);
1222 => [ 2000040100:00:00, [ Spring ],
1223 2000040112:00:00, [ Spring, Event3 ],
1224 2000040113:00:00, [ Spring ] ]
1225
1226 Events_List("2000-03-15","2000-04-10");
1227 => [ 2000031500:00:00, [ Winter ],
1228 2000032200:00:00, [ Spring ]
1229 2000040112:00:00, [ Spring, Event3 ]
1230 2000040113:00:00, [ Spring ] ]
1231
1232 Much more complicated events can be defined using recurrences.
1233
1234 When $flag is non-zero, the format of the output is changed. If $flag
1235 is 1, then a tally of the amount of time given to each event is returned.
1236 Time for which two or more events apply is counted for both.
1237
1238 Events_List("2000-03-15","2000-04-10",1);
1239 => { Winter => +0:0:1:0:0:0:0,
1240 Spring => +0:0:2:5:0:0:0,
1241 Event3 => +0:0:0:0:1:0:0 }
1242
1243 When $flag is 2, a more complex tally with no event counted twice is
1244 returned.
1245
1246 Events_List("2000-03-15","2000-04-10",2);
1247 => { Winter => +0:0:1:0:0:0:0,
1248 Spring => +0:0:2:4:23:0:0,
1249 Event3+Spring => +0:0:0:0:1:0:0 }
1250
1251 The hash contains one element for each combination of events.
1252
1253 =item B<Date_DayOfWeek>
1254
1255 $day = Date_DayOfWeek($m,$d,$y);
1256
1257 Returns the day of the week (1 for Monday, 7 for Sunday).
1258
1259 All arguments must be numeric.
1260
1261 =item B<Date_SecsSince1970>
1262
1263 $secs = Date_SecsSince1970($m,$d,$y,$h,$mn,$s);
1264
1265 Returns the number of seconds since Jan 1, 1970 00:00 (negative if date is
1266 earlier).
1267
1268 All arguments must be numeric.
1269
1270 =item B<Date_SecsSince1970GMT>
1271
1272 $secs = Date_SecsSince1970GMT($m,$d,$y,$h,$mn,$s);
1273
1274 Returns the number of seconds since Jan 1, 1970 00:00 GMT (negative if date
1275 is earlier). If CurrTZ is "IGNORE", the number will be identical to
1276 Date_SecsSince1970 (i.e. the date given will be treated as being in GMT).
1277
1278 All arguments must be numeric.
1279
1280 =item B<Date_DaysSince1BC>
1281
1282 $days = Date_DaysSince1BC($m,$d,$y);
1283
1284 Returns the number of days since Dec 31, 1BC. This includes the year 0000.
1285
1286 All arguments must be numeric.
1287
1288 =item B<Date_DayOfYear>
1289
1290 $day = Date_DayOfYear($m,$d,$y);
1291
1292 Returns the day of the year (001 to 366)
1293
1294 All arguments must be numeric.
1295
1296 =item B<Date_NthDayOfYear>
1297
1298 ($y,$m,$d,$h,$mn,$s) = Date_NthDayOfYear($y,$n);
1299
1300 Returns the year, month, day, hour, minutes, and decimal seconds given
1301 a floating point day of the year.
1302
1303 All arguments must be numeric. $n must be greater than or equal to 1
1304 and less than 366 on non-leap years and 367 on leap years.
1305
1306 NOTE: When $n is a decimal number, the results are non-intuitive perhaps.
1307 Day 1 is Jan 01 00:00. Day 2 is Jan 02 00:00. Intuitively, you
1308 might think of day 1.5 as being 1.5 days after Jan 01 00:00, but this
1309 would mean that Day 1.5 was Jan 02 12:00 (which is later than Day 2).
1310 The best way to think of this function is a time line starting at 1 and
1311 ending at 366 (in a non-leap year). In terms of a delta, think of $n
1312 as the number of days after Dec 31 00:00 of the previous year.
1313
1314 =item B<Date_DaysInYear>
1315
1316 $days = Date_DaysInYear($y);
1317
1318 Returns the number of days in the year (365 or 366)
1319
1320 =item B<Date_DaysInMonth>
1321
1322 $days = Date_DaysInMonth($m,$y);
1323
1324 Returns the number of days in the month.
1325
1326 =item B<Date_WeekOfYear>
1327
1328 $wkno = Date_WeekOfYear($m,$d,$y,$first);
1329
1330 Figure out week number. $first is the first day of the week which is
1331 usually 1 (Monday) or 7 (Sunday), but could be any number between 1 and 7
1332 in practice.
1333
1334 All arguments must be numeric.
1335
1336 NOTE: This routine should only be called in rare cases. Use UnixDate with
1337 the %W, %U, %J, %L formats instead. This routine returns a week between 0
1338 and 53 which must then be "fixed" to get into the ISO-8601 weeks from 1 to
1339 53. A date which returns a week of 0 actually belongs to the last week of
1340 the previous year. A date which returns a week of 53 may belong to the
1341 first week of the next year.
1342
1343 =item B<Date_LeapYear>
1344
1345 $flag = Date_LeapYear($y);
1346
1347 Returns 1 if the argument is a leap year
1348 Written by David Muir Sharnoff <[email protected]>
1349
1350 =item B<Date_DaySuffix>
1351
1352 $day = Date_DaySuffix($d);
1353
1354 Add `st', `nd', `rd', `th' to a date (i.e. 1st, 22nd, 29th). Works for
1355 international dates.
1356
1357 =item B<Date_TimeZone>
1358
1359 $tz = Date_TimeZone;
1360
1361 This determines and returns the local time zone. If it is unable to determine
1362 the local time zone, the following error occurs:
1363
1364 ERROR: Date::Manip unable to determine Time Zone.
1365
1366 See The TIME ZONES section below for more information.
1367
1368 =item B<Date_ConvTZ>
1369
1370 $date = Date_ConvTZ($date);
1371 $date = Date_ConvTZ($date,$from);
1372 $date = Date_ConvTZ($date,"",$to [,$errlev]);
1373 $date = Date_ConvTZ($date,$from,$to [,$errlev]);
1374
1375 This converts a date (which MUST be in the format returned by ParseDate)
1376 from one time zone to another.
1377
1378 If it is called with no arguments, the date is converted from the local
1379 time zone to the time zone specified by the config variable ConvTZ (see
1380 documentation on ConvTZ below). If ConvTZ is set to "IGNORE", no
1381 conversion is done.
1382
1383 If called with $from but no $to, the time zone is converted from the
1384 time zone in $from to ConvTZ (of TZ if ConvTZ is not set). Again, no
1385 conversion is done if ConvTZ is set to "IGNORE".
1386
1387 If called with $to but no $from, $from defaults to ConvTZ (if set) or the
1388 local time zone otherwise. Although this does not seem immediately obvious,
1389 it actually makes sense. By default, all dates that are parsed are
1390 converted to ConvTZ, so most of the dates being worked with will be stored
1391 in that time zone.
1392
1393 If Date_ConvTZ is called with both $from and $to, the date is converted
1394 from the time zone $from to $to.
1395
1396 NOTE: As in all other cases, the $date returned from Date_ConvTZ has no
1397 time zone information included as part of it, so calling UnixDate with the
1398 "%z" format will return the time zone that Date::Manip is working in
1399 (usually the local time zone).
1400
1401 Example: To convert 2/2/96 noon PST to CST (regardless of what time zone
1402 you are in, do the following:
1403
1404 $date = ParseDate("2/2/96 noon");
1405 $date = Date_ConvTZ($date,"PST","CST");
1406
1407 Both time zones MUST be in one of the formats listed below in the section
1408 TIME ZONES.
1409
1410 If an error occurs, $errlev determines what happens:
1411
1412 0 : the program dies
1413 1 : a warning is produced and nothing is returned
1414 2 : the function silently returns nothing
1415
1416 =item B<Date_IsWorkDay>
1417
1418 $flag = Date_IsWorkDay($date [,$flag]);
1419
1420 This returns 1 if $date is a work day. If $flag is non-zero, the time is
1421 checked to see if it falls within work hours. It returns an empty string
1422 if $date is not valid.
1423
1424 =item B<Date_NextWorkDay>
1425
1426 $date = Date_NextWorkDay($date,$off [,$flag]);
1427
1428 Finds the day $off work days from now. If $flag is non-zero, we must also
1429 take into account the time of day.
1430
1431 If $flag is zero, day 0 is today (if today is a workday) or the
1432 next work day if it isn't. In any case, the time of day is unaffected.
1433
1434 If $flag is non-zero, day 0 is now (if now is part of a workday) or the
1435 start of the very next work day.
1436
1437 =item B<Date_PrevWorkDay>
1438
1439 $date = Date_PrevWorkDay($date,$off [,$flag]);
1440
1441 Similar to Date_NextWorkDay.
1442
1443 =item B<Date_NearestWorkDay>
1444
1445 $date = Date_NearestWorkDay($date [,$tomorrowfirst]);
1446
1447 This looks for the work day nearest to $date. If $date is a work day, it
1448 is returned. Otherwise, it will look forward or backwards in time 1 day
1449 at a time until a work day is found. If $tomorrowfirst is non-zero (or if
1450 it is omitted and the config variable TomorrowFirst is non-zero), we look
1451 to the future first. Otherwise, we look in the past first. In other words,
1452 in a normal week, if $date is Wednesday, $date is returned. If $date is
1453 Saturday, Friday is returned. If $date is Sunday, Monday is returned. If
1454 Wednesday is a holiday, Thursday is returned if $tomorrowfirst is non-nil
1455 or Tuesday otherwise.
1456
1457 =item B<DateManipVersion>
1458
1459 $version = DateManipVersion;
1460
1461 Returns the version of Date::Manip.
1462
1463 =back
1464
1465 =head1 TIME ZONES
1466
1467 With the release of Date::Manip 6.00, time zones and daylight saving
1468 time are now fully supported in Date::Manip. 6.00 uses information from
1469 several standards (most importantly the Olson zoneinfo database) to get
1470 a list of all known time zones.
1471
1472 Unfortunately, 6.00 requires a newer version of perl, so I will continue
1473 to support the 5.xx release for a while. However, the way I will support
1474 time zones in 5.xx has changed. Previously, new time zones would be added
1475 on request. That is no longer the case. Time zones for 5.xx are now generated
1476 automatically from those available in 6.00.
1477
1478 The following time zone names are currently understood (and can be used in
1479 parsing dates). These are zones defined in RFC 822.
1480
1481 Universal: GMT, UT
1482 US zones : EST, EDT, CST, CDT, MST, MDT, PST, PDT
1483 Military : A to Z (except J)
1484 Other : +HHMM or -HHMM
1485 ISO 8601 : +HH:MM, +HH, -HH:MM, -HH
1486
1487 In addition, the following time zone abbreviations are also accepted. These
1488 do not come from a standard, but were included in previous releases of
1489 Date::Manip 5.xx and are preserved here for backward compatibility:
1490
1491 IDLW -1200 International Date Line West
1492 NT -1100 Nome
1493 SAT -0400 Chile
1494 CLDT -0300 Chile Daylight
1495 AT -0200 Azores
1496 MEWT +0100 Middle European Winter
1497 MEZ +0100 Middle European
1498 FWT +0100 French Winter
1499 GB +0100 GMT with daylight savings
1500 SWT +0100 Swedish Winter
1501 MESZ +0200 Middle European Summer
1502 FST +0200 French Summer
1503 METDST +0200 An alias for MEST used by HP-UX
1504 EETDST +0300 An alias for eest used by HP-UX
1505 EETEDT +0300 Eastern Europe, USSR Zone 1
1506 BT +0300 Baghdad, USSR Zone 2
1507 IT +0330 Iran
1508 ZP4 +0400 USSR Zone 3
1509 ZP5 +0500 USSR Zone 4
1510 IST +0530 Indian Standard
1511 ZP6 +0600 USSR Zone 5
1512 AWST +0800 Australian Western Standard
1513 ROK +0900 Republic of Korea
1514 AEST +1000 Australian Eastern Standard
1515 ACDT +1030 Australian Central Daylight
1516 CADT +1030 Central Australian Daylight
1517 AEDT +1100 Australian Eastern Daylight
1518 EADT +1100 Eastern Australian Daylight
1519 NZT +1200 New Zealand
1520 IDLE +1200 International Date Line East
1521
1522 All other time zone abbreviations come from the standards. In many
1523 cases, an abbreviation may be used for multiple time zones. For
1524 example, NST stands for Newfoundland Standard -0330 and North Sumatra
1525 +0630. In these cases, only 1 of the two is available. I have tried
1526 to use the most recent definition, and of those (if multiple time zones
1527 use the abbreviation), the most commonly used. I don't claim that I'm
1528 correct in all cases, but I've done the best I could.
1529
1530 The list of abbreviations available is documented in the
1531 Date::Manip::DM5abbrevs document.
1532
1533 Date::Manip must be able to determine the time zone the user is in. It does
1534 this by looking in the following places:
1535
1536 $Date::Manip::TZ (set with Date_Init or in Manip.pm)
1537 $ENV{TZ}
1538 the Unix `date` command (if available)
1539 $main::TZ
1540 /etc/TIMEZONE
1541 /etc/time zone
1542
1543 At least one of these should contain a time zone in one of the supported
1544 forms. If none do by default, the TZ variable must be set with Date_Init.
1545
1546 The time zone may be in the STD#DST format (in which case both abbreviations
1547 must be in the table above) or any of the formats described above. The
1548 STD#DST format is NOT available when parsing a date however. The following
1549 forms are also available and are treated similar to the STD#DST forms:
1550
1551 US/Pacific
1552 US/Mountain
1553 US/Central
1554 US/Eastern
1555 Canada/Pacific
1556 Canada/Mountain
1557 Canada/Central
1558 Canada/Eastern
1559
1560 =head1 CUSTOMIZING DATE::MANIP
1561
1562 There are a number of variables which can be used to customize the way
1563 Date::Manip behaves. There are also several ways to set these variables.
1564
1565 At the top of the Manip.pm file, there is a section which contains all
1566 customization variables. These provide the default values.
1567
1568 These can be overridden in a global config file if one is present (this
1569 file is optional). If the GlobalCnf variable is set in the Manip.pm file,
1570 it contains the full path to a config file. If the file exists, its
1571 values will override those set in the Manip.pm file. A sample config file
1572 is included with the Date::Manip distribution. Modify it as appropriate
1573 and copy it to some appropriate directory and set the GlobalCnf variable in
1574 the Manip.pm file.
1575
1576 Each user can have a personal config file which is of the same form as the
1577 global config file. The variables PersonalCnf and PersonalCnfPath set the
1578 name and search path for the personal config file. This file is also
1579 optional. If present, it overrides any values set in the global file.
1580
1581 NOTE: if you use business mode calculations, you must have a config file
1582 (either global or personal) since this is the only place where you can
1583 define holidays.
1584
1585 Finally, any variables passed in through Date_Init override all other
1586 values.
1587
1588 A config file can be composed of several sections. The first section sets
1589 configuration variables. Lines in this section are of the form:
1590
1591 VARIABLE = VALUE
1592
1593 For example, to make the default language French, include the line:
1594
1595 Language = French
1596
1597 Only variables described below may be used. Blank lines and lines beginning
1598 with a pound sign (#) are ignored. All spaces are optional and strings are
1599 case insensitive.
1600
1601 A line which starts with an asterisk (*) designates a new section. For
1602 example, the HOLIDAY section starts with a line:
1603
1604 *Holiday
1605
1606 The various sections are defined below.
1607
1608 =head1 DATE::MANIP VARIABLES
1609
1610 All Date::Manip variables which can be used are described in the following
1611 section.
1612
1613 =over 4
1614
1615 =item B<IgnoreGlobalCnf>
1616
1617 If this variable is used (any value is ignored), the global config file
1618 is not read. It must be present in the initial call to Date_Init or the
1619 global config file will be read.
1620
1621 =item B<EraseHolidays>
1622
1623 If this variable is used (any value is ignored), the current list of
1624 defined holidays is erased. A new set will be set the next time a
1625 config file is read in. This can be set in either the global config file
1626 or as a Date_Init argument (in which case holidays can be read in from
1627 both the global and personal config files) or in the personal config file
1628 (in which case, only holidays in the personal config file are counted).
1629
1630 =item B<PathSep>
1631
1632 This is a regular expression used to separate multiple paths. For example,
1633 on Unix, it defaults to a colon (:) so that multiple paths can be written
1634 PATH1:PATH2 . For Win32 platforms, it defaults to a semicolon (;) so that
1635 paths such as "c:\;d:\" will work.
1636
1637 =item B<GlobalCnf>
1638
1639 This variable can be passed into Date_Init to point to a global
1640 configuration file. The value must be the complete path to a config file.
1641
1642 By default, no global config file is read. Any time a global config file
1643 is read, the holidays are erased.
1644
1645 Paths may have a tilde (~) expansion on platforms where this is supported
1646 (currently Unix and VMS).
1647
1648 =item B<PersonalCnf>
1649
1650 This variable can be passed into Date_Init or set in a global config file
1651 to set the name of the personal configuration file.
1652
1653 The default name for the config file is .DateManip.cnf on all Unix
1654 platforms and Manip.cnf on all non-Unix platforms (because some of them
1655 insist on 8.3 character filenames :-).
1656
1657 =item B<PersonalCnfPath>
1658
1659 This is a list of paths separated by the separator specified by the PathSep
1660 variable. These paths are each checked for the PersonalCnf config file.
1661
1662 Paths may have a tilde (~) expansion on platforms where this is supported
1663 (currently Unix and VMS).
1664
1665 =item B<Language>
1666
1667 Date::Manip can be used to parse dates in many different languages.
1668 Currently, it is configured to read the following languages (the version
1669 in which they added is included for historical interest):
1670
1671 English (default)
1672 French (5.02)
1673 Swedish (5.05)
1674 German (5.31)
1675 Dutch (5.32) aka Nederlands
1676 Polish (5.32)
1677 Spanish (5.33)
1678 Portuguese (5.34)
1679 Romanian (5.35)
1680 Italian (5.35)
1681 Russian (5.41)
1682 Turkish (5.41)
1683 Danish (5.41)
1684
1685 Others can be added easily. Language is set to the language used to parse
1686 dates. If you are interested in providing a translation for a new
1687 language, email me (see the AUTHOR section below) and I'll send you a list
1688 of things that I need.
1689
1690 =item B<DateFormat>
1691
1692 Different countries look at the date 12/10 as Dec 10 or Oct 12. In the
1693 United States, the first is most common, but this certainly doesn't hold
1694 true for other countries. Setting DateFormat to "US" forces the first
1695 behavior (Dec 10). Setting DateFormat to anything else forces the second
1696 behavior (Oct 12).
1697
1698 =item B<TZ>
1699
1700 If set, this defines the local time zone. See the TIME ZONES section above
1701 for information on its format.
1702
1703 =item B<ConvTZ>
1704
1705 All date comparisons and calculations must be done in a single time zone in
1706 order for them to work correctly. So, when a date is parsed, it should be
1707 converted to a specific time zone. This allows dates to easily be compared
1708 and manipulated as if they are all in a single time zone.
1709
1710 The ConvTZ variable determines which time zone should be used to store dates
1711 in. If it is left blank, all dates are converted to the local time zone
1712 (see the TZ variable above). If it is set to one of the time zones listed
1713 above, all dates are converted to this time zone. Finally, if it is set to
1714 the string "IGNORE", all time zone information is ignored as the dates are
1715 read in (in this case, the two dates "1/1/96 12:00 GMT" and "1/1/96 12:00
1716 EST" would be treated as identical).
1717
1718 =item B<Internal>
1719
1720 When a date is parsed using ParseDate, that date is stored in an internal
1721 format which is understood by the Date::Manip routines UnixDate and
1722 DateCalc. Originally, the format used to store the date internally was:
1723
1724 YYYYMMDDHH:MN:SS
1725
1726 It has been suggested that I remove the colons (:) to shorten this to:
1727
1728 YYYYMMDDHHMNSS
1729
1730 The main advantage of this is that some databases are colon delimited which
1731 makes storing a date from Date::Manip tedious.
1732
1733 In order to maintain backwards compatibility, the Internal variable was
1734 introduced. Set it to 0 (to use the old format) or 1 (to use the new
1735 format).
1736
1737 =item B<FirstDay>
1738
1739 It is sometimes necessary to know what day of week is regarded as first.
1740 By default, this is set to Monday, but many countries and people will
1741 prefer Sunday (and in a few cases, a different day may be desired). Set
1742 the FirstDay variable to be the first day of the week (1=Monday, 7=Sunday)
1743 Monday should be chosen to to comply with ISO 8601.
1744
1745 =item B<WorkWeekBeg, WorkWeekEnd>
1746
1747 The first and last days of the work week. By default, Monday and Friday.
1748 WorkWeekBeg must come before WorkWeekEnd numerically. The days are
1749 numbered from 1 (Monday) to 7 (Sunday).
1750
1751 There is no way to handle an odd work week of Thu to Mon for example or 10
1752 days on, 4 days off.
1753
1754 =item B<WorkDay24Hr>
1755
1756 If this is non-nil, a work day is treated as being 24 hours long. The
1757 WorkDayBeg and WorkDayEnd variables are ignored in this case.
1758
1759 =item B<WorkDayBeg, WorkDayEnd>
1760
1761 The times when the work day starts and ends. WorkDayBeg must come before
1762 WorkDayEnd (i.e. there is no way to handle the night shift where the work
1763 day starts one day and ends another). Also, the workday MUST be more than
1764 one hour long (of course, if this isn't the case, let me know... I want a
1765 job there!).
1766
1767 The time in both can be in any valid time format (including international
1768 formats), but seconds will be ignored.
1769
1770 =item B<TomorrowFirst>
1771
1772 Periodically, if a day is not a business day, we need to find the nearest
1773 business day to it. By default, we'll look to "tomorrow" first, but if this
1774 variable is set to 0, we'll look to "yesterday" first. This is only used in
1775 the Date_NearestWorkDay and is easily overridden (see documentation for that
1776 function).
1777
1778 =item B<DeltaSigns>
1779
1780 Prior to Date::Manip version 5.07, a negative delta would put negative
1781 signs in front of every component (i.e. "0:0:-1:-3:0:-4"). By default,
1782 5.07 changes this behavior to print only 1 or two signs in front of the
1783 year and day elements (even if these elements might be zero) and the sign
1784 for year/month and day/hour/minute/second are the same. Setting this
1785 variable to non-zero forces deltas to be stored with a sign in front of
1786 every element (including elements equal to 0).
1787
1788 =item B<Jan1Week1>
1789
1790 ISO 8601 states that the first week of the year is the one which contains
1791 Jan 4 (i.e. it is the first week in which most of the days in that week
1792 fall in that year). This means that the first 3 days of the year may
1793 be treated as belonging to the last week of the previous year. If this
1794 is set to non-nil, the ISO 8601 standard will be ignored and the first
1795 week of the year contains Jan 1.
1796
1797 =item B<YYtoYYYY>
1798
1799 By default, a 2 digit year is treated as falling in the 100 year period of
1800 CURR-89 to CURR+10. YYtoYYYY may be set to any integer N to force a 2
1801 digit year into the period CURR-N to CURR+(99-N). A value of 0 forces
1802 the year to be the current year or later. A value of 99 forces the year
1803 to be the current year or earlier. Since I do no checking on the value of
1804 YYtoYYYY, you can actually have it any positive or negative value to force
1805 it into any century you want.
1806
1807 YYtoYYYY can also be set to "C" to force it into the current century, or
1808 to "C##" to force it into a specific century. So, in 1998, "C" forces
1809 2 digit years to be 1900-1999 and "C18" would force it to be 1800-1899.
1810
1811 It can also be set to the form "C####" to force it into a specific 100
1812 year period. C1950 refers to 1950-2049.
1813
1814 =item B<UpdateCurrTZ>
1815
1816 If a script is running over a long period of time, the time zone may change
1817 during the course of running it (i.e. when daylight saving time starts or
1818 ends). As a result, parsing dates may start putting them in the wrong time
1819 zone. Since a lot of overhead can be saved if we don't have to check the
1820 current time zone every time a date is parsed, by default checking is turned
1821 off. Setting this to non-nil will force time zone checking to be done every
1822 time a date is parsed... but this will result in a considerable performance
1823 penalty.
1824
1825 A better solution would be to restart the process on the two days per year
1826 where the time zone switch occurs.
1827
1828 =item B<IntCharSet>
1829
1830 If set to 0, use the US character set (7-bit ASCII) to return strings such
1831 as the month name. If set to 1, use the appropriate international character
1832 set. For example, If you want your French representation of December to
1833 have the accent over the first "e", you'll want to set this to 1.
1834
1835 =item B<ForceDate>
1836
1837 This variable can be set to a date in the format: YYYY-MM-DD-HH:MN:SS
1838 to force the current date to be interpreted as this date. Since the current
1839 date is used in parsing, this string will not be parsed and MUST be in the
1840 format given above.
1841
1842 =item B<TodayIsMidnight>
1843
1844 If set to a true value (e.g. 1), then "today" will mean the same as
1845 "midnight today"; otherwise it will mean the same as "now".
1846
1847 =back
1848
1849 =head1 HOLIDAY SECTION
1850
1851 The holiday section of the config file is used to define holidays. Each
1852 line is of the form:
1853
1854 DATE = HOLIDAY
1855
1856 HOLIDAY is the name of the holiday (or it can be blank in which case the
1857 day will still be treated as a holiday... for example the day after
1858 Thanksgiving or Christmas is often a work holiday though neither are
1859 named).
1860
1861 DATE is a string which can be parsed to give a valid date in any year. It
1862 can be of the form
1863
1864 Date
1865 Date + Delta
1866 Date - Delta
1867 Recur
1868
1869 A valid holiday section would be:
1870
1871 *Holiday
1872
1873 1/1 = New Year's Day
1874 third Monday in Feb = Presidents' Day
1875 fourth Thu in Nov = Thanksgiving
1876
1877 # The Friday after Thanksgiving is an unnamed holiday most places
1878 fourth Thu in Nov + 1 day =
1879
1880 1*0:0:0:0:0:0*EASTER = Easter
1881 1*11:0:11:0:0:0*DWD = Veteran's Day (observed)
1882 1*0:0:0:0:0:0*EASTER,PD5 = Good Friday
1883
1884 In a Date + Delta or Date - Delta string, you can use business mode by
1885 including the appropriate string (see documentation on DateCalc) in the
1886 Date or Delta. So (in English), the first workday before Christmas could
1887 be defined as:
1888
1889 12/25 - 1 business day =
1890
1891 The dates may optionally contain the year. For example, the dates
1892
1893 1/1
1894 1/1/1999
1895
1896 refers to Jan 1 in any year or in only 1999 respectively. For dates that
1897 refer to any year, the date must be written such that by simply appending
1898 the year (separated by spaces) it can be correctly interpreted. This
1899 will work for everything except ISO 8601 dates, so ISO 8601 dates may
1900 not be used in this case.
1901
1902 Note that the dates are specified in whatever format is set using the
1903 Date_Init options, so if the standard parsing is D/M/YYYY, you would
1904 need to specify it as:
1905
1906 25/12/2002 = Christmas
1907
1908 In cases where you are interested in business type calculations, you'll
1909 want to define most holidays using recurrences, since they can define
1910 when a holiday is celebrated in the financial world. For example,
1911 Christmas should be defined as:
1912
1913 1*12:0:24:0:0:0*FW1 = Christmas
1914
1915 NOTE: It was pointed out to me that using a similar type recurrence to
1916 define New Years does not work. The recurrence:
1917
1918 1*12:0:31:0:0:0*FW1
1919
1920 fails (worse, it goes into an infinite loop). The problem is that each
1921 holiday definition is applied to a specific year and it expects to find
1922 the holiday for that year. When this recurrence is applied to the year
1923 1995, it returns the holiday for 1996 and fails.
1924
1925 Use the recurrence:
1926
1927 1*1:0:1:0:0:0*NWD
1928
1929 instead.
1930
1931 If you wanted to define both Christmas and Boxing days (Boxing is the
1932 day after Christmas, and is celebrated in some parts of the world), you
1933 could do it in one of the following ways:
1934
1935 1*12:0:24:0:0:0*FW1 = Christmas
1936 1*12:0:25:0:0:0*FW1 = Boxing
1937
1938 1*12:0:24:0:0:0*FW1 = Christmas
1939 01*12:0:24:0:0:0*FW1 = Boxing
1940
1941 1*12:0:24:0:0:0*FW1 = Christmas
1942 1*12:0:25:0:0:0*FW1,a = Boxing
1943
1944 The following examples will NOT work:
1945
1946 1*12:0:24:0:0:0*FW1 = Christmas
1947 1*12:0:24:0:0:0*FW2 = Boxing
1948
1949 1*12:0:24:0:0:0*FW1 = Christmas
1950 1*12:0:24:0:0:0*FW1 = Boxing
1951
1952 The reasoning behind all this is as follows:
1953
1954 Holidays go into affect the minute they are parsed. So, in the case of:
1955
1956 1*12:0:24:0:0:0*FW1 = Christmas
1957 1*12:0:24:0:0:0*FW2 = Boxing
1958
1959 the minute the first line is parsed, Christmas is defined as a holiday.
1960 The second line then steps forward 2 work days (skipping Christmas since
1961 that's no longer a work day) and define the work day two days after
1962 Christmas, NOT the day after Christmas.
1963
1964 An good alternative would appear to be:
1965
1966 1*12:0:24:0:0:0*FW1 = Christmas
1967 1*12:0:24:0:0:0*FW1 = Boxing
1968
1969 This unfortunately fails because the recurrences are currently stored in a
1970 hash. Since these two recurrences are identical, they fail (the first one
1971 is overwritten by the second and in essence, Christmas is never defined).
1972
1973 To fix this, make them unique with either a fake flag (which is ignored):
1974
1975 1*12:0:24:0:0:0*FW1,a = Boxing
1976
1977 or adding an innocuous 0 somewhere:
1978
1979 01*12:0:24:0:0:0*FW1 = Boxing
1980
1981 The other good alternative would be to make two completely different
1982 recurrences such as:
1983
1984 1*12:0:24:0:0:0*FW1 = Christmas
1985 1*12:0:25:0:0:0*FW1 = Boxing
1986
1987 At times, you may want to switch back and forth between two holiday files.
1988 This can be done by calling the following:
1989
1990 Date_Init("EraseHolidays=1","PersonalCnf=FILE1");
1991 ...
1992 Date_Init("EraseHolidays=1","PersonalCnf=FILE2");
1993 ...
1994
1995 =head1 EVENTS SECTION
1996
1997 The Events section of the config file is similar to the Holiday section.
1998 It is used to name certain days or times, but there are a few important
1999 differences:
2000
2001 =over 4
2002
2003 =item B<Events can be assigned to any time and duration>
2004
2005 All holidays are exactly 1 day long. They are assigned to a period
2006 of time from midnight to midnight.
2007
2008 Events can be based at any time of the day, and may be of any duration.
2009
2010 =item B<Events don't affect business mode calculations>
2011
2012 Unlike holidays, events are completely ignored when doing business
2013 mode calculations.
2014
2015 =back
2016
2017 Whereas holidays were added with business mode math in mind, events
2018 were added with calendar and scheduling applications in mind.
2019
2020 Every line in the events section is of the form:
2021
2022 EVENT = NAME
2023
2024 where NAME is the name of the event, and EVENT defines when it occurs
2025 and its duration. An EVENT can be defined in the following ways:
2026
2027 Date
2028 Date*
2029
2030 Date ; Date
2031 Date ; Delta
2032
2033 Here, Date* refers to a string containing a Date with NO TIME fields
2034 (Jan 12, 1/1/2000, 2010-01-01) while Date does contain time fields.
2035 Similarly, Recur* stands for a recurrence with the time fields all
2036 equal to 0) while Recur stands for a recurrence with at least one
2037 non-zero time field.
2038
2039 Both Date* and Recur* refer to an event very similar to a holiday which
2040 goes from midnight to midnight.
2041
2042 Date and Recur refer to events which occur at the time given and with
2043 a duration of 1 hour.
2044
2045 Events given by "Date ; Date", "Date ; Delta", and "Recur ; Delta"
2046 contain both the starting date and either ending date or duration.
2047
2048 Events given as three elements "Date ; Delta ; Delta" or "Recur ; Delta ;
2049 Delta" take a date and add both deltas to it to give the starting and
2050 ending time of the event. The order and sign of the deltas is
2051 unimportant (and both can be the same sign to give a range of times
2052 which does not contain the base date).
2053
2054 =head1 KNOWN PROBLEMS
2055
2056 The following are not bugs in Date::Manip, but they may give some people
2057 problems.
2058
2059 =over 4
2060
2061 =item B<Unable to determine Time Zone>
2062
2063 Perhaps the most common problem occurs when you get the error:
2064
2065 Error: Date::Manip unable to determine Time Zone.
2066
2067 Date::Manip tries hard to determine the local time zone, but on some
2068 machines, it cannot do this (especially non-Unix systems). To fix this,
2069 just set the TZ variable, either at the top of the Manip.pm file, in the
2070 DateManip.cnf file, or in a call to Date_Init. I suggest using the form
2071 "EST5EDT" so you don't have to change it every 6 months when going to or
2072 from daylight saving time.
2073
2074 Windows NT does not seem to set the time zone by default. From the
2075 Perl-Win32-Users mailing list:
2076
2077 > How do I get the TimeZone on my NT?
2078 >
2079 > $time_zone = $ENV{'TZ'};
2080 >
2081 You have to set the variable before, WinNT doesn't set it by
2082 default. Open the properties of "My Computer" and set a SYSTEM
2083 variable TZ to your time zone. [email protected]
2084
2085 This might help out some NT users.
2086
2087 A minor (false) assumption that some users might make is that since
2088 Date::Manip passed all of its tests at install time, this should not occur
2089 and are surprised when it does.
2090
2091 Some of the tests are time zone dependent. Since the tests all include
2092 input and expected output, I needed to know in advance what time zone they
2093 would be run in. So, the tests all explicitly set the time zone using the
2094 TZ configuration variable passed into Date_Init. Since this overrides any
2095 other method of determining the time zone, Date::Manip uses this and doesn't
2096 have to look elsewhere for the time zone.
2097
2098 When running outside the tests, Date::Manip has to rely on its other
2099 methods for determining the time zone.
2100
2101 =item B<Missing date formats>
2102
2103 Please see the Date::Manip::Problems document for a discussion.
2104
2105 =item B<Complaining about getpwnam/getpwuid>
2106
2107 Another problem is when running on Micro$oft OS's. I have added many
2108 tests to catch them, but they still slip through occasionally. If any ever
2109 complain about getpwnam/getpwuid, simply add one of the lines:
2110
2111 $ENV{OS} = Windows_NT
2112 $ENV{OS} = Windows_95
2113
2114 to your script before
2115
2116 use Date::Manip
2117
2118 =item B<Date::Manip is slow>
2119
2120 The reasons for this are covered in the SHOULD I USE DATE::MANIP section
2121 above.
2122
2123 Some things that will definitely help:
2124
2125 Version 5.21 does run noticeably faster than earlier versions due to
2126 rethinking some of the initialization, so at the very least, make sure you
2127 are running this version or later.
2128
2129 ISO-8601 dates are parsed first and fastest. Use them whenever possible.
2130
2131 Avoid parsing dates that are referenced against the current time (in 2
2132 days, today at noon, etc.). These take a lot longer to parse.
2133
2134 Example: parsing 1065 dates with version 5.11 took 48.6 seconds, 36.2
2135 seconds with version 5.21, and parsing 1065 ISO-8601 dates with version
2136 5.21 took 29.1 seconds (these were run on a slow, overloaded computer with
2137 little memory... but the ratios should be reliable on a faster computer).
2138
2139 Business date calculations are extremely slow. You should consider
2140 alternatives if possible (i.e. doing the calculation in exact mode and
2141 then multiplying by 5/7). Who needs a business date more accurate
2142 than "6 to 8 weeks" anyway, right :-)
2143
2144 Never call Date_Init more than once. Unless you're doing something very
2145 strange, there should never be a reason to anyway.
2146
2147 =item B<Sorting Problems>
2148
2149 If you use Date::Manip to sort a number of dates, you must call Date_Init
2150 either explicitly, or by way of some other Date::Manip routine before it
2151 is used in the sort. For example, the following code fails:
2152
2153 use Date::Manip;
2154 # Date_Init;
2155 sub sortDate {
2156 my($date1, $date2);
2157 $date1 = ParseDate($a);
2158 $date2 = ParseDate($b);
2159 return (Date_Cmp($date1,$date2));
2160 }
2161 @dates = ("Fri 16 Aug 96",
2162 "Mon 19 Aug 96",
2163 "Thu 15 Aug 96");
2164 @i=sort sortDate @dates;
2165
2166 but if you uncomment the Date_Init line, it works. The reason for this is
2167 that the first time you call Date_Init, it initializes a number of items
2168 used by Date::Manip. Some of these have to be sorted (regular expressions
2169 sorted by length to ensure the longest match). It turns out that Perl
2170 has a bug in it which does not allow a sort within a sort. At some point,
2171 this should be fixed, but for now, the best thing to do is to call Date_Init
2172 explicitly. The bug exists in all versions up to 5.005 (I haven't
2173 tested 5.6.0 yet).
2174
2175 NOTE: This is an EXTREMELY inefficient way to sort data (but read the 2nd
2176 note below for an easy way to correct this). Instead, you should parse the
2177 dates with ParseDate, sort them using a normal string comparison, and then
2178 convert them back to the format desired using UnixDate.
2179
2180 NOTE: It has been reported to me that you can still use ParseDate
2181 to sort dates in this way, and be quite efficient through the use of
2182 Memoize. Just add the following lines to your code:
2183
2184 use Date::Manip;
2185 use Memoize;
2186 memoize('ParseDate');
2187 ...
2188 @i=sort sortDate @dates;
2189
2190 Since sortDate would call ParseDate with the same data over and over,
2191 this is a perfect application for the Memoize module. So, sorting with
2192 ParseDate is no longer slow for sorting.
2193
2194 =item B<RCS Control>
2195
2196 If you try to put Date::Manip under RCS control, you are going to have
2197 problems. Apparently, RCS replaces strings of the form "$Date...$" with
2198 the current date. This form occurs all over in Date::Manip. To prevent the
2199 RCS keyword expansion, checkout files using "co -ko". Since very few people
2200 will ever have a desire to do this (and I don't use RCS), I have not worried
2201 about it.
2202
2203 =back
2204
2205 =head1 KNOWN BUGS
2206
2207 =over 4
2208
2209 =item B<Daylight Saving Times>
2210
2211 Date::Manip 5.xx does not handle daylight saving time, though it does handle
2212 time zones to a certain extent. Converting from EST to PST works fine.
2213 Going from EST to PDT is unreliable.
2214
2215 The following examples are run in the winter of the US East coast (i.e.
2216 in the EST time zone).
2217
2218 print UnixDate(ParseDate("6/1/97 noon"),"%u"),"\n";
2219 => Sun Jun 1 12:00:00 EST 1997
2220
2221 June 1 EST does not exist. June 1st is during EDT. It should print:
2222
2223 => Sun Jun 1 00:00:00 EDT 1997
2224
2225 Even explicitly adding the time zone doesn't fix things (if anything, it
2226 makes them worse):
2227
2228 print UnixDate(ParseDate("6/1/97 noon EDT"),"%u"),"\n";
2229 => Sun Jun 1 11:00:00 EST 1997
2230
2231 Date::Manip converts everything to the current time zone (EST in this case).
2232
2233 Related problems occur when trying to do date calculations over a time zone
2234 change. These calculations may be off by an hour.
2235
2236 Also, if you are running a script which uses Date::Manip over a period of
2237 time which starts in one time zone and ends in another (i.e. it switches
2238 form Daylight Saving Time to Standard Time or vice versa), many things may
2239 be wrong (especially elapsed time).
2240
2241 These problems will not be fixed in Date::Manip 5.xx. Date::Manip 6.xx has
2242 full support for time zones and daylight saving time.
2243
2244 =back
2245
2246 =head1 BUGS AND QUESTIONS
2247
2248 Please refer to the Date::Manip::Problems documentation for
2249 information on submitting bug reports or questions to the author.
2250
2251 =head1 SEE ALSO
2252
2253 Date::Manip - main module documentation
2254
2255 =head1 LICENSE
2256
2257 This script is free software; you can redistribute it and/or
2258 modify it under the same terms as Perl itself.
2259
2260 =head1 AUTHOR
2261
2262 Sullivan Beck (https://github.com/SBECK-github/)
2263
2264 =cut