Debian Codegraph @

lib/Date/Manip/Date.pod

raw
1 # Copyright (c) 1995-2026 Sullivan Beck. All rights reserved.
2 # This program is free software; you can redistribute it and/or modify it
3 # under the same terms as Perl itself.
4
5 =pod
6
7 =head1 NAME
8
9 Date::Manip::Date - Methods for working with dates
10
11 =head1 SYNOPSIS
12
13 use Date::Manip::Date;
14 $date = new Date::Manip::Date;
15
16 =head1 DESCRIPTION
17
18 This module works specifically with date objects.
19
20 Although the word date is used extensively here, it is actually
21 somewhat misleading. Date::Manip works with the full calendar date
22 (year, month, day, and week when appropriate), time of day (hour,
23 minute, second), and time zone. It doesn't work with fractional
24 seconds.
25
26 =head1 METHODS
27
28 =over 4
29
30 =item B<base>
31
32 =item B<config>
33
34 =item B<err>
35
36 =item B<is_date>
37
38 =item B<is_delta>
39
40 =item B<is_recur>
41
42 =item B<new>
43
44 =item B<new_config>
45
46 =item B<new_date>
47
48 =item B<new_delta>
49
50 =item B<new_recur>
51
52 =item B<tz>
53
54 Please refer to the Date::Manip::Obj documentation for these methods.
55
56 =item B<calc>
57
58 $date2 = $date->calc($delta [,$subtract]);
59 $delta = $date->calc($date2 [,$subtract] [,$mode]);
60
61 Please refer to the Date::Manip::Calc documentation for details.
62
63 =item B<cmp>
64
65 $val = $date1->cmp($date2);
66
67 This compares two different dates (both of which must be valid date
68 objects). It returns -1, 0, or 1 similar to the cmp or <=> operators
69 in perl. The comparison will automatically handle time zone differences
70 between the two dates (i.e. they will be sorted in order as they
71 appear in the GMT zone).
72
73 A warning is printed if either of the date objects does not include
74 a valid date.
75
76 =item B<complete>
77
78 $flag = $date->complete([$field]);
79
80 This tests the date stored in the object to see if it is complete or
81 truncated (see below for a discussion of this).
82
83 If no $field is passed in, it returns 1 if the date is complete, or
84 0 if it was truncated and default values have been supplied.
85
86 If $field is passed in, it may be one of: m, d, h, mn, s . It will
87 return 1 if the value for that field was specified, or 0 if a
88 default was used.
89
90 =item B<convert>
91
92 $err = $date->convert([$zone]);
93
94 This converts the date stored in the object to a different time zone.
95 $zone can be the name of a time zone. If it is not passed in, the
96 date is converted to the local time zone.
97
98 =item B<holiday>
99
100 $name = $date->holiday();
101 @name = $date->holiday();
102 $name = $date->event();
103
104 This returns the name of the holiday if $date is a holiday. If $date
105 is not a holiday, undef is returned. If $date is an unnamed holiday,
106 an empty string is returned.
107
108 In scalar context, holiday returns the name of one holiday that occurs
109 on that date (the one first defined in the config file). In list
110 context, it returns all holidays on that date.
111
112 =item B<input>
113
114 $str = $date->input();
115
116 This returns the string that was parsed to form the date.
117
118 =item B<is_business_day>
119
120 $flag = $date->is_business_day($checktime);
121
122 This returns 1 if $date is a business day.
123
124 $checktime may be passed in. If it is non-zero, the time is checked to
125 see if the date is a business day and falls within work hours.
126
127 =item B<list_holidays>
128
129 @date = $date->list_holidays([$y]);
130
131 This returns a list of Date::Manip::Date objects containing all dates
132 during a year which are holidays. The times will all be 00:00:00.
133
134 If $y is not passed in, it will list the holidays in the same year as
135 the date stored in $date (if any) or in the current year otherwise.
136
137 =item B<list_events>
138
139 @list = $date->list_events( [$format] );
140 @list = $date->list_events(0 [,$format]);
141 @list = $date->list_events($date1 [,$format]);
142
143 This returns a list of events. Events are defined in the Events section
144 of the config file (discussed in the Date::Manip::Holidays manual).
145
146 In the first form, a list of all events active at the precise time
147 stored in $date will be returned.
148
149 If the first argument evaluates to 0, a list of all events active at
150 any time during that day (Y,M,D) are returned.
151
152 If the first argument is another date object, all events that are active
153 at any time between the two dates (inclusive) are returned.
154
155 By default, the list returned is of the form:
156
157 ( [START, END, NAME],
158 [START, END, NAME],
159 ...
160 )
161
162 where START is a date object when an event starts, END is a date
163 object when it ends, and NAME is the name of the event. Note that
164 START and END are the actual start and end date of the event and may
165 be outside the range of dates being examined (though the event will
166 obviously overlap the range or it wouldn't be included in the list).
167
168 If $format is included, it can specify an alternate format for the
169 output. Currently, the only supported format is named "dates" and
170 it returns a list in the form:
171
172 ( [DATE1, NAME1a, NAME1b, ...],
173 [DATE2, NAME2a, NAME2b, ...],
174 ...
175 )
176
177 This includes a list of all dates during the range when there is a
178 change in what events are active. DATE1 will always be the start of
179 the range being considered, and (NAME1a, NAME1b, ...) are the
180 list of all events that will be active at that time. At DATE2,
181 the list of active events changes with (NAME2a, NAME2b, ...) being
182 active.
183
184 It is quite possible that a date be included which has no active
185 events, and in that case, the list of names will be empty.
186
187 =item B<nearest_business_day>
188
189 $date->nearest_business_day([$tomorrowfirst]);
190
191 This looks for the work day nearest to $date. If $date is a work day,
192 it is left unmodified. Otherwise, it will look forward or backwards
193 in time 1 day at a time until a work day is found. If $tomorrowfirst
194 is non-zero (or if it is omitted and the config variable TomorrowFirst
195 is non-zero), we look to the future first. Otherwise, we look in the
196 past first. In other words, in a normal week, if $date is Wednesday,
197 $date is returned. If $date is Saturday, Friday is returned. If
198 $date is Sunday, Monday is returned. If Wednesday is a holiday,
199 Thursday is returned if $tomorrowfirst is non-nil or Tuesday
200 otherwise.
201
202 =item B<next_business_day>
203
204 =item B<prev_business_day>
205
206 $date->next_business_day($off [,$checktime]);
207 $date->prev_business_day($off [,$checktime]);
208
209 The next_business_day method sets the given date to $off (which can be
210 a positive integer or zero) business days in the future. The prev_business_day
211 method sets the date to $off business days in the past.
212
213 First, $date is tested. If $checktime is nonzero, the date must fall
214 on a business date, and during business hours. If $checktime is zero,
215 the time check is not done, and the date must simply fall on a
216 business date.
217
218 If the check fails, the date is moved to the start of the next
219 business day (if $checktime is nonzero) or the next business day at
220 the current time (if $checktime is zero). Otherwise, it is left
221 unmodified.
222
223 Next, if $off is greater than 0, the day $off work days from now is
224 determined.
225
226 One thing to note for the prev_business_day method is that if $date
227 check fails, the date is set to the next business date, exactly like
228 next_business_day. In other words, if $date is not a business day, the
229 call:
230
231 $date->prev_business_day(0 [,$checktime]);
232
233 moves $date forward in time instead of backward which is nonintuitive,
234 but you just have to think of day 0 as being the next business day if
235 $date is not a business day.
236
237 As a result, the following two calls ALWAYS give the same result:
238
239 $date->next_business_day(0 [,$checktime]);
240 $date->prev_business_day(0 [,$checktime]);
241
242 no matter what date is stored in $date.
243
244 =item B<parse>
245
246 $err = $date->parse($string [,@opts]);
247
248 This parses a string which should include a valid date and stores
249 it in the object. If the string does not include a valid date, an
250 error is returned. Use the err method to see the full error
251 message.
252
253 A full date may include a calendar date (year, month, day), a time of
254 day (hour, minute, second), and time zone information. All of this can
255 be entered in many different formats.
256
257 For information on valid date formats, refer to the section VALID
258 DATE FORMATS. For information on valid time zone information, refer
259 to the section VALID TIME ZONE FORMATS.
260
261 If no time zone information is included in the date, it is treated
262 as being in the local time zone.
263
264 If time zone information is included, the date will be kept in that
265 time zone, and all operations will be done in that time zone. The
266 convert method can be used to change the time zone to the local time
267 zone, or to another time zone.
268
269 Some things to note:
270
271 All strings are case insensitive. "December" and "DEceMBer" are
272 equivalent.
273
274 When a part of the date is not given, defaults are used. This is
275 described below in the section "Complete vs. truncated dates and times".
276
277 The year may be entered as 2 or 4 digits. If entered as 2 digits, it will
278 be converted to a 4 digit year. There are several ways to do this based on
279 the value of the YYtoYYYY config variable. Refer to the Date::Manip::Config
280 documentation for more details.
281
282 Dates are always checked to make sure they are valid.
283
284 If any other arguments are passed in, they act as options which may
285 improve the speed of parsing. These include:
286
287 noiso8601 Do not try to parse the
288 date as an ISO 8601 date
289 or time.
290 nodow Do not try to parse a
291 day-of-week (Monday) in
292 the string.
293 nocommon Do not try to parse the
294 date using the formats
295 in the "Common date
296 formats" section.
297 noother Do not try to parse the
298 date using the "Less common
299 date formats" or a time
300 using the "Other time
301 formats".
302 nospecial Do not try to parse the
303 date using the "Special
304 date strings" formats
305 or a time using the
306 "Special time strings"
307 formats, or as a
308 combined date/time using
309 the "Additional combined
310 date and time" formats.
311 nodelta Do not treat deltas as
312 a date relative to now.
313 noholidays Do not parse holiday
314 names as dates.
315
316 =item B<parse_date>
317
318 $err = $date->parse_date($string [,@opts]);
319
320 This parses a string which contains a valid date and sets the date
321 part of the object.
322
323 If the object contained a valid date, the time is kept unchanged. If the
324 object did NOT contain a valid date, a time of 00:00:00 is used.
325
326 @opts can be any of the strings described in the parse method above.
327
328 =item B<parse_time>
329
330 $err = $date->parse_time($string [,@opts]);
331
332 This parses a string and sets the time portion of $date to contain it.
333
334 If the object contained a valid date, the Y/M/D portion is left unchanged.
335 Otherwise, the current date is used.
336
337 @opts can be 'noiso8601' or 'noother'.
338
339 =item B<parse_format>
340
341 $err = $date->parse_format($format,$string);
342 ($err,%match) = $date->parse_format($format,$string);
343
344 This will parse a date contained in $string based on explicit format
345 information contained in $format.
346
347 If the format is invalid, $err will contain an error message.
348 If the format is valid, but string doesn't match, an error code
349 of 1 is returned.
350
351 If called in array context, a hash will be returned containing %+.
352 This is primarily useful if the $format string contains some
353 named capture groups that you define. This is discussed below.
354
355 $format is a string containing a regular expression with some special
356 directives (based on the printf directives). These directives are turned
357 into regular expression components, and then the entire string is turned
358 into a regular expression which, if $string matches it, will return the
359 date.
360
361 The directives available are identical to the printf directives. So,
362 if your $format string contains the directive '%Y', it will match a
363 4-digit year.
364
365 All of the printf directives are available here with a few caveats:
366
367 %l This directive is NOT available.
368
369 %b,%h,%B These will all match a month name or abbreviation.
370
371 %v,%a,%A These will all match a day name or abbreviation.
372
373 %z,%Z,%N These will match any time zone string.
374
375 %n Multi-line matching is not currently supported,
376 so this directive is not allowed.
377
378 %x All format directives are converted to a regular
379 expression and then cached (so that a format
380 can be reused without the penalty of doing the
381 conversion to a regular expression with each use).
382 As a result, if you need to set the DateFormat config
383 variable (which determines the meaning of the %x
384 directive), it must be done before a format string
385 containing %x is used. If the DateFormat config variable
386 is set afterwards, the format string will reflect the
387 old, NOT THE NEW, value of DateFormat.
388
389 The format string may not over-specify the date. In other words, you
390 may not include both a %y and %Y directive or both a %j and %m directive.
391
392 A valid format string will specify any of the following sets of data:
393
394 Required Optional
395
396 M D H Mn S Y Zone Day-of-week
397 M D H Mn Y Zone Day-of-week
398 M D Y Zone Day-of-week
399 H Mn S Zone
400 H Mn Zone
401
402 For example, if you had a date stored as:
403
404 YYYY.MM-DD
405
406 you could match it using the following:
407
408 $date->parse_format('%Y\\.%m\\-%d',$string);
409
410 If you wanted to extract the date from an apache log line:
411
412 10.11.12.13 - - [17/Aug/2009:12:33:30 -0400] "GET /favicon.ico ...
413
414 you could use:
415
416 $date->parse_format('.*?\\[%d/%b/%Y:%T %z\\].*',$line);
417
418 When matching months, days, and hours, there are two directives
419 that could be used (for numerical versions). For the month, you
420 may use %m or %f. If your date is known to have a two-digit month,
421 you should use %m. If it contains a one- or two-digit month, you must
422 use %f (and it is safe to use %f for two-digit months). Similarly,
423 for days, you can use %d or %e and for hours you can use %H or %k. In
424 both cases, the first can only be used if you are guaranteed a 2-digit
425 value.
426
427 In your format string, you may use capture groups (or back references
428 to them) in the regular expression using all of the rules of normal
429 regular expressions. Since Date::Manip uses named capture groups
430 internally, it is suggested that you also use named groups. Mixing
431 numbered and named groups will work... but it'll be entirely up to you
432 to keep track of what numbers refer to which capture groups.
433
434 Every printf directive adds one or more named capture groups to the
435 regular expression. If you use named groups in the format string,
436 they must not conflict with the ones used internally, or else the
437 date will probably not be parsed correctly.
438
439 The following named capture groups are used internally:
440
441 y
442 m
443 d
444 h
445 mn
446 s
447 mon_name
448 mon_abb
449 dow_name
450 dow_abb
451 dow_char
452 dow_num
453 doy
454 nth
455 ampm
456 epochs
457 epocho
458 tzstring
459 off
460 abb
461 zone
462 g
463 w
464 l
465 u
466
467 To be safe, it is suggested that any additional named capture groups
468 introduced by the programmer start with a capital letter. This is
469 guaranteed to never conflict with any existing, or future named capture
470 groups.
471
472 In order to get access to the values stored in the additional named
473 capture groups, the parse_format function must be called in list
474 context, and the %+ array will be returned as the second value.
475
476 As an example:
477
478 $string = "before 2014-01-25 after";
479 ($err,%m) = $date->parse_format('(?<PRE>.*?)%Y-%m-%d(?<POST>.*)',$string);
480
481 would return a hash (%m) with the following key/value pairs:
482
483 'PRE' => 'before '
484 'POST' => ' after'
485
486 =item B<prev>
487
488 =item B<next>
489
490 The prev method changes the date to the previous (or current)
491 occurrence of either a day of the week, a certain time of day, or
492 both. The next method changes the date to the next (or current)
493 occurrence. The examples below illustrate the prev method, but
494 the next one is identical in operation.
495
496 There are two different ways to use this method. The first is to pass
497 in a day of week and possibly a time:
498
499 $err = $date->prev($dow, $curr [,$time]);
500
501 If $curr = 0, this means to look for the previous occurrence of the day
502 of week, and set the time to the value passed in (or current time if
503 no time was passed in). The day is ALWAYS less than the current day. If
504 the current day is the same day of week as $dow, then the date
505 returned will be one week earlier.
506
507 If $curr = 1, it means to look for the current or previous occurrence
508 of the day of week, and set the time to the value passed in (or 00:00:00 if
509 none was passed in). If the current day of week is the same as $dow, the
510 date will remain unchanged. Since the time is then set, the new date may
511 actually occur after the original date depending on the value of $time.
512
513 If $curr = 2, it means to look for the last time (not counting now)
514 that the day of week at the given time occurred. The date may be the
515 same as the original date.
516
517 $time may be a list reference of [H,MN,S], [H,MN], or [H].
518
519 The following examples should illustrate the use of this function.
520
521 Original Date = Fri Nov 22 18:15:00
522
523 dow curr time new date
524
525 4 (Thu) 0/1/2 undef Thu Nov 21 00:00:00
526 4 0/1/2 [12,30,0] Thu Nov 21 12:30:00
527
528 5 (Fri) 0/2 undef Fri Nov 15 18:15:00
529 5 1 undef Fri Nov 22 18:15:00
530
531 5 0 [12,30,0] Fri Nov 15 12:30:00
532 5 1/2 [12,30,0] Fri Nov 22 12:30:00
533
534 5 0/2 [19,30,0] Fri Nov 15 19:30:00
535 5 1 [19,30,0] Fri Nov 22 19:30:00
536
537 The second way to use this method is by passing in undef for the day of
538 week.
539
540 $err = $date->prev(undef,$curr,$time);
541
542 In this case, a time is required and it must be a list reference
543 of 3 elements: [H, MN, S]. Any or all of the elements may be undef.
544
545 The new date is the previous occurrence of the time.
546
547 If you define hours, then minutes and seconds may be defined, or
548 default to 0 and you are looking for a previous time that the
549 specified time (HH:00:00) occurred (which might be as much as 24 hours
550 in the past).
551
552 If hours are undefined and minutes are defined, then seconds may be
553 defined, or default to 0, and you are looking for the last time the
554 minutes/seconds (MN:SS) appeared on the digital clock, which will be
555 sometime in the past hour.
556
557 Finally, if hours and minutes are undefined, seconds must be defined
558 (or default to zero) and the last time that that second occurred will
559 be returned (which will be sometime in the past minute).
560
561 If $curr is non-zero, the current time is returned if it matches the
562 criteria passed in, so the returned value will be now or in the past.
563 If $curr is zero, the time returned will definitely be in the past.
564
565 DATE = Fri Nov 22 18:15:00
566
567 curr hr min sec returns
568 0/1 18 undef undef Nov 22 18:00:00
569 0/1 18 30 0 Nov 21 18:30:00
570 0 18 15 undef Nov 21 18:15:00
571 1 18 15 undef Nov 22 18:15:00
572 0 undef 15 undef Nov 22 17:15:00
573 1 undef 15 undef Nov 22 18:15:00
574
575 =item B<printf>
576
577 $out = $date->printf($in);
578 @out = $date->printf(@in);
579
580 This takes a string or list of strings which may contain any number of
581 special formatting directives. These directives are replaced with
582 information contained in the date. Everything else in the string is
583 returned unmodified.
584
585 A directive always begins with '%'. They are described in the section
586 below in the section PRINTF DIRECTIVES.
587
588 =item B<secs_since_1970_GMT>
589
590 $secs = $date->secs_since_1970_GMT();
591
592 This returns the number of seconds that have elapsed since Jan 1, 1970
593 00:00:00 GMT (negative if the date is earlier).
594
595 The reverse is also allowed:
596
597 $err = $date->secs_since_1970_GMT($secs);
598
599 which sets the date to $secs seconds from Jan 1, 1970 00:00:00 GMT in
600 the local time zone.
601
602 =item B<set>
603
604 $err = $date->set($field,@vals [,$isdst]);
605
606 This explicitly sets one or more fields in a date.
607
608 $field can be any of the following:
609
610 $field @vals
611
612 zone [ZONE] ZONE can be any zone or alias
613
614 zdate [ZONE,]DATE sets the zone and entire date
615
616 date DATE sets the entire date
617
618 time TIME sets the entire time
619
620 y YEAR sets one field
621 m MONTH
622 d DAY
623 h HOUR
624 mn MINUTE
625 s SECOND
626
627 Here, DATE is a list reference containing [Y,M,D,H,MN,S] and TIME is
628 a list reference containing [H,MN,S].
629
630 ZONE is optional (it defaults to the local zone as defined either by
631 the system clock, or the SetDate or ForceDate config variables). If it
632 is passed in, it can be any zone name, abbreviation, or offset. An
633 offset can be expressed either as a valid offset string, or as a list
634 reference. Refer to the join/split functions of Date::Manip::Base for
635 information on valid offset strings.
636
637 An optional last argument is $isdst (which must be 0 or 1) is included
638 when setting a date which could be in either standard time or daylight
639 saving time. It is ignored in all other situations. If it is
640 not included, and the resulting date could be in either, it will
641 default to standard time.
642
643 The $date object must contain a valid date (unless the entire date
644 is being set with $field set to either "zdate" or "date").
645
646 If $field is "zone", the time zone of the date will be set. If ZONE is
647 not passed in, it will be set to the local time zone. When setting the
648 time zone, no conversion is done! Whatever date and time is stored in
649 the $date object prior to this remains unchanged... except it will
650 be that date and time in the new time zone.
651
652 If $field is "zdate", the entire date and time zone is set. If ZONE is
653 not passed in, it is set to the local time zone.
654
655 If $field is "date", the entire date will be set, but the time zone
656 of the date will not be changed.
657
658 If $field is "time", or one of the individual fields, only those
659 fields will be modified.
660
661 An error is returned if an invalid argument list is passed in, or if
662 the resulting date is checked and found to be invalid.
663
664 =item B<value>
665
666 $val = $date->value([$type]);
667 @val = $date->value([$type]);
668
669 These return the value of the date stored in the object.
670
671 In scalar context, a printable string in the form YYYYMMDDHH:MN:SS
672 is returned. In list context, a list is returned of (Y,M,D,H,MN,S).
673
674 If $type is omitted, the date is returned in the time zone it was
675 parsed in.
676
677 If $type is "local", it is returned in the local time zone (which
678 is either the system time zone, or the zone specified with the
679 SetDate or ForceDate config variables).
680
681 If $type is "gmt", the date is returned in the GMT time zone.
682
683 An empty string or list is returned in the case of an error (and
684 an error code is set).
685
686 =item B<week_of_year>
687
688 $wkno = $date->week_of_year([$first]);
689
690 This figures out the week number for the date stored in $date. It uses
691 the config variables FirstDay and Week1ofYear to determine this. For
692 historical reasons, an argument $first may be passed in. It must be
693 between 1 and 7 and refers to the first day of the week and overrides
694 whatever the FirstDay variable is set to.
695
696 NOTE: This routine should only be called in rare cases. Use printf
697 with the %W, %U, %J, %L formats instead as that will always return the
698 correct values for week and year.
699
700 This routine returns a week between 0 and 53 which must then be
701 "fixed" to get into the ISO 8601 weeks from 1 to 53. A date which
702 returns a week of 0 actually belongs to the last week of the previous
703 year. A date which returns a week of 53 may belong to the first week
704 of the next year.
705
706 =back
707
708 =head1 ISSUES WITH PARSING DATES
709
710 The following issues may occur when parsing dates that should be
711 understood to make full use of this module.
712
713 =over 4
714
715 =item B<Complete vs. truncated dates and times>
716
717 Date formats are either complete or truncated. A complete date fully
718 specifies the year, month, and day and a complete time fully specifies
719 the hour, minute, and second.
720
721 It should be understood that in many instances, the information may be
722 implied rather than explicitly stated, but it is still treated as
723 complete.
724
725 For example, the date "January 3" is complete because it implies the
726 current year.
727
728 A truncated calendar date or time does not include information about
729 some of the fields. Date::Manip will never work with a partial date or
730 time, so defaults will be supplied.
731
732 For example, the date "2009-01" is missing a day field, so a default
733 will be used. In this case, the day will be the 1st, so this is
734 equivalent to "Jan 1st 2009". If only the year is given, it will
735 default to Jan 1.
736
737 If the time, or any of it's components is missing, they default to
738 00. So the time "12:30" and "12:30:00" are equivalent.
739
740 The "complete" method can be used to check what type of date was
741 parsed, and which values were specified (either explicitly or implied)
742 and which were provided as a default. It should be noted that there
743 is no way to differentiate between an explicit and implied value.
744
745 A string with a date and/or time may consist of any of the following:
746
747 a complete date and a time (complete or truncated)
748 a truncated date with no time
749 a time (complete or truncated) with no date
750
751 In other words, the date "Jan 2009 12:30" is not valid since it consists
752 of a time with a truncated date.
753
754 =back
755
756 =head1 VALID TIME ZONE FORMATS
757
758 When specifying a time zone, it can be done in three different ways.
759 One way is to specify the actual time zone. The second is to supply
760 a valid time zone abbreviation. The third is to specify an offset (with
761 an optional abbreviation). The following dates illustrate the these
762 formats.
763
764 The timezone information always follows the time immediately, and may
765 only be included if a time is included. The following examples use
766 an ISO 8601 format for the date/time, but any of the other date and
767 time formats may be used.
768
769 The first way to specify the time zone is to specify it by complete name
770 (or using one of the standard aliases):
771
772 2001-07-01-00:00:00 America/New_York
773
774 Although this is unambiguous when it comes to determining the time zone,
775 the time is ambiguous in most zones for one hour of the year. When
776 a time change occurs during which the clock is moved back, the same
777 wall clock time occurs twice.
778
779 For example, in America/New_York, on Sunday, Nov 2, 2008, at 02:00 in
780 the morning, the clock was set back to 01:00. As a result, the date
781 Nov 2, 2008 at 01:30 is ambiguous. It is impossible to determine if
782 this refers to the 01:30 that occurred half an hour before the time
783 change, or the one 30 minute after the change.
784
785 In practice, if this form is used, the date will be assigned to
786 standard time, meaning that there will be some times (typically 1 hour
787 per year) which cannot be expressed this way. As such, this method is
788 discouraged.
789
790 The second way to specify the time zone, which is the most common, is
791 to use a time zone abbreviation:
792
793 2001-07-01-00:00:00 EDT
794
795 Unfortunately, the abbreviation does not uniquely determine the
796 time zone except in a few cases. In order to assign a time zone,
797 Date::Manip will refer to a list of all time zones which use the
798 abbreviation. They will be tested, in the order given in the
799 Date::Manip::Zones documentation, and the first match (i.e. the one in
800 which the given date/time and abbreviation are valid) determines the
801 time zone which will be used. A great deal of effort has been made to
802 ensure that the most likely time zone will be obtained (i.e. the most
803 common time zones are tested before less common ones), so in most
804 cases, the desired results will be obtained.
805
806 If the default order does not yield the desired time zone, the order of
807 testing can be modified using the abbrev method described in the
808 Date::Manip::TZ documentation.
809
810 Although the time zone is ambiguous, the date is not, since only
811 time zones for which the date are valid will be used.
812
813 The third way to specify the time zone is by specifying an offset and
814 an optional abbreviation:
815
816 2001-07-01-00:00:00 -04
817 2001-07-01-00:00:00 -0400
818 2001-07-01-00:00:00 -040000
819 2001-07-01-00:00:00 -04:00
820 2001-07-01-00:00:00 -04:00:00
821
822 2001-07-01-00:00:00 -04 (EDT)
823 2001-07-01-00:00:00 -0400 (EDT)
824 2001-07-01-00:00:00 -040000 (EDT)
825 2001-07-01-00:00:00 -04:00 (EDT)
826 2001-07-01-00:00:00 -04:00:00 (EDT)
827
828 2001-07-01-00:00:00 -04 EDT
829 2001-07-01-00:00:00 -0400 EDT
830 2001-07-01-00:00:00 -040000 EDT
831 2001-07-01-00:00:00 -04:00 EDT
832 2001-07-01-00:00:00 -04:00:00 EDT
833
834 As with the abbreviation, the offset is almost never sufficient to
835 uniquely determine the time zone (and it is not even guaranteed that
836 both the offset and abbreviation will, though in practice, it is
837 probably sufficient). In this instance, the time zone will be
838 determined by testing all time zones which have the given offset (and
839 abbreviation if it is included) until one is found which matches the
840 pieces of information supplied. For more information about how this
841 testing is done, refer to the def_zone method of the Date::Manip::TZ
842 documentation.
843
844 =head1 VALID DATE FORMATS
845
846 There are several categories of date formats supported by Date::Manip.
847 These are strings which specify only the year/month/day fields.
848
849 These formats explicitly set the date, but not the time. These formats
850 may be combined with a time string (as specified below) to set both
851 the date and time. If this is not done, the default time is determined
852 by the DefaultTime config variable.
853
854 =over 4
855
856 =item B<ISO 8601 dates>
857
858 The preferred date formats are those specified by ISO 8601. The
859 specification includes valid calendar date and valid time formats.
860 Date::Manip will handle all of these formats, but does not require
861 that the dates rigidly adhere to the specification since the ultimate
862 goal of Date::Manip is to handle dates as they are represented in
863 real life and some common variations exist which are similar to, but
864 not identical to, those from the specification.
865
866 A calendar date includes the following fields:
867
868 CC 2-digit representation of the century
869 YY 2-digit representation of the year in
870 a century
871 MM 2-digit representation of a month
872 DD 2-digit representation of a day of month
873 DoY 3-digit representation of a day of year
874 (001-366)
875 Www the character "W" followed by a 2-digit
876 week of the year (01-53)
877 D the day of the week (1-7)
878
879 The following date formats are considered complete by Date::Manip. In
880 the following, the date Thu Mar 5 2009 is used as an example. This is
881 the 64th day of the year. Thu is the 4th day of the week. The week
882 starting Mon, Mar 2 is the 10th week of the year (according the the
883 ISO 8601 definition). Obviously, some of the formats are only valid
884 when used at some times. For example, the format --MMDD refers to a
885 month and day in the current year, so the date Mar 5, 2009 can only be
886 specified using this format during 2009.
887
888 Format Notes Examples
889
890 CCYYMMDD 20090305
891 CCYY-MM-DD 2009-03-05
892
893 YYMMDD 1,2,4 090305
894 YY-MM-DD 09-03-05
895
896 -YYMMDD 3,4 -090305
897 -YY-MM-DD -09-03-05
898
899 --MMDD 1 --0305
900 --MM-DD --03-05
901
902 ---DD 1 ---05
903
904
905 CCYYDoY 2009064
906 CCYY-DoY 2009-064
907
908 YYDoY 1,4 09064
909 YY-DoY 09-064
910
911 -YYDoY 3,4 -09064
912 -YY-DoY -09-064
913
914 -DoY 1 -064
915
916
917 CCYYWwwD 2009W104
918 CCYY-Www-D 2009-W10-4
919
920 YYWwwD 1,4 09W104
921 YY-Www-D 09-W10-4
922
923 -YYWwwD 3,4 -09W104
924 -YY-Www-D -09-W10-4
925
926 -YWwwD 1 -9W104
927 -Y-Www-D -9-W10-4
928 Y is the year (0-9) in
929 current decade
930
931 -WwwD 1 -W104
932 -Www-D -W10-4
933
934 -W-D 1 -W-4
935 D is day (1-7) in
936 current week
937
938 ---D 1 ---4
939 same as -W-D
940
941 The following date formats are truncated:
942
943 CCYY-MM 2 2009-03 (2009-03-01)
944
945 CCYY 2009 (2009-01-01)
946
947 CC 2 20 (2000-01-01)
948
949 -YYMM 4 -0903
950 -YY-MM -09-03
951
952 -YY 4 -09
953
954 --MM --03
955
956 CCYYWww 2009W10
957 CCYY-Www 2009-W10
958
959 YYWww 4 09W10
960 YY-Www 09-W10
961
962 -YYWww 3,4 -09W10
963 -YY-Www -09-W10
964
965 -Www -W10
966
967 Notes:
968
969 1 These formats are considered truncated in the standard, but since
970 they do include (or imply, using the current date for defaults)
971 all of the fields, and since they do not introduce any parsing
972 complexities, the standard is relaxed, and they are treated as
973 complete.
974
975 2 These formats are treated differently than in Date::Manip 5.xx as
976 described below.
977
978 3 These formats are not defined in the ISO 8601 spec, but
979 are added for the sake of completeness since they do not
980 add any parsing incompatibilities.
981
982 4 Formats where the century is not given are described as a year in
983 the current century in the specification. Date::Manip treats this
984 more generically using the YYtoYYYY config variable. This will be
985 used to determine how to determine the full year.
986
987 Date::Manip 5.xx handled ISO 8601 dates in a less rigid fashion, and
988 deviated from the specification in several formats. As of 6.00, the
989 specification is followed much more closely so that all of the date
990 formats included in it should produce valid dates. This changes, in a
991 backwards incompatible way, the way a few strings will be interpreted
992 as dates.
993
994 As of 6.00, a two-digit date will be treated as CC. Previously, it
995 was treated as YY.
996
997 A six-digit date will be treated as YYMMDD. Previously, it was treated
998 as YYYYMM.
999
1000 Previously, dashes were treated as optional in many cases. According
1001 to the specification, dates may be written in expanded form (with all
1002 dashes present) or abbreviate form (with no dashes). As of 6.00, this
1003 is the behavior, so the formats: YYMMDD and YY-MM-DD are allowed, as
1004 per the specification, but the format YY-MMDD is NOT allowed (though
1005 it was previously).
1006
1007 The Www-D formats require a bit of explanation. According to the
1008 specification, the date:
1009
1010 1996-w02-3
1011
1012 refers to the day with an ordinal number of 3 within the calendar week
1013 in the 2nd week of 1996.
1014
1015 In the specification, the days of the week are numbered from 1 to 7
1016 (Monday to Sunday), and the week always begins on Monday, so day 1
1017 (Monday) is always the first day of the week, day 2 (Tuesday) is
1018 always the second day of the week, etc.
1019
1020 In Date::Manip, the constraint that the week must start with Monday is
1021 relaxed, allowing the week to begin with Sunday (a far more common
1022 start of the week in calendars, at least in some parts of the world).
1023
1024 This presents a problem though in that the above date could be
1025 interpreted as Wednesday (day 3) of the 2nd week of 1996, or as the
1026 3rd day of the 2nd week of 1996 (which would normally be Wednesday,
1027 but would be Tuesday if the week begins on Sunday).
1028
1029 As of Date::Manip 6.00, the above date will be interpreted as the 3rd
1030 day of the 2nd week. This is a reversal from Date::Manip 5.xx, but I
1031 believe is what the specification would require. For more information,
1032 refer to the Date::Manip::Changes document.
1033
1034 =item B<Common date formats>
1035
1036 Date::Manip supports a number of common date formats. The following fields
1037 may be included in a date:
1038
1039 YY 2-digit representation of the year
1040 YYYY 4-digit representation of the year
1041 M 1- or 2- digit representation of the month
1042 MM 2-digit representation of the month
1043 D 1- or 2- digit representation of the day
1044 DD 2-digit representation of the day
1045 mmm The abbreviated or full month name (i.e. Jan)
1046
1047 The following date formats are supported:
1048
1049 Format Notes Examples
1050
1051 M/D 1,2,3 3/5
1052 M/D/YY 1 3/5/09
1053 M/D/YYYY 1 3/5/2009
1054
1055 YYYY/M/D 2009/3/5
1056
1057 mmm/D Mar/5
1058 mmm/D/YY Mar/5/09
1059 mmm/D/YYYY Mar/5/2009
1060 D/mmm 5/Mar
1061 D/mmm/YY 5/Mar/09
1062 D/mmm/YYYY 5/Mar/2009
1063 YYYY/mmm/D 2009/Mar/5
1064
1065 mmmD Mar5
1066 mmmDDYY 4 Mar0509
1067 mmmDDYYYY Mar052009
1068 Dmmm 5Mar
1069 DmmmYY 5Mar09
1070 DmmmYYYY 5Mar2009
1071 YYYYmmmD 2009Mar5
1072
1073 mmmD YY Mar5 09
1074 mmmD YYYY Mar5 2009
1075 Dmmm YY 5Mar 09
1076 Dmmm YYYY 5Mar 2009
1077
1078 mmm/D YY Mar/5 09
1079 mmm/D YYYY Mar/5 2009
1080 D/mmm YY 5/Mar 09
1081 D/mmm YYYY 5/Mar 2009
1082
1083 YY mmmD 09 Mar5
1084 YYYY mmmD 2009 Mar5
1085 YY Dmmm 09 5Mar
1086 YYYY Dmmm 2009 5Mar
1087
1088 YY mmm/D 09 Mar/5
1089 YYYY mmm/D 2009 Mar/5
1090 YY D/mmm 09 5/Mar
1091 YYYY D/mmm 2009 5/Mar
1092
1093 YYYY:MM:DD 2010:01:15 (EXIF format)
1094
1095 mmmYYYY 4 Jun 2010
1096 YYYYmmm 4 2010 June
1097 mmm/YYYY 4 Jun/2010
1098 YYYY/mmm 4 2010/Jun
1099
1100 In the formats above, the slash (/) can be replace by any of the valid
1101 separators: whitespace, slash (/), period (.), or dash (-). The dash,
1102 though allowed, is discouraged since it may conflict with an ISO 8601
1103 format. For example, the format MM/DD/YY is just fine, but MM-DD-YY
1104 does not work since it conflicts with YY-MM-DD. To be safe, if "-" is
1105 used as a separator in a non-ISO format, they should be turned into
1106 "/" before calling the Date::Manip routines or you should use the 'noiso8601'
1107 option with the B<parse> or B<parse_date> methods.
1108
1109 No matter what separator is used, the same separator must be used
1110 throughout the date. For example, MM/DD/YY is valid and MM.DD.YY is
1111 also valid, but MM/DD.YY is NOT valid.
1112
1113 Notes:
1114
1115 1 With these formats, Americans tend to write month first, but many
1116 other countries tend to write day first. The latter behavior can be
1117 obtained by setting the config variable DateFormat to something other
1118 than "US".
1119
1120 2 The dot (.) separator may not be used in the M/D format since it
1121 will be interpreted as the H12,H+ format described below.
1122
1123 3 The M/D format should not use the period (.) separator as that will
1124 incorrectly match the HH,H+ time format.
1125
1126 4 Historically, I have not supported partial dates (i.e. dates that
1127 were not fully specified), but it has been argued that something like
1128 'Jun 1910' would be interpreted by almost everyone as a day in June
1129 of 1910 instead of June 19, 2010. And it has been shown that in
1130 some applications, dates are specified in that way. I have added the
1131 new config variable Format_MMMYYYY which will change this. If this
1132 variable is not set, the formats allowed are:
1133
1134 mmmDDYY
1135
1136 If it is set, the formats allowed are:
1137
1138 mmmYYYY
1139 YYYYmmm
1140
1141 The day of week may not be included with these formats. When
1142 parsing a full date/time, if Format_MMMYYYY is set to 'first',
1143 it returns the 1st of the month at midnight. If it is set to
1144 'last', it returns the last day at 23:59:59. If parsing only
1145 only a date, it will be set to the first or last day of the
1146 month at midnight.
1147
1148 These formats explicitly set the date, but not the time. The default
1149 time is determined by the DefaultTime config variable.
1150
1151 =item B<Less common date formats>
1152
1153 The following formats are also supported by Date::Manip:
1154
1155 DoW
1156 The day of week of the current week
1157 Friday
1158 Friday at 12:40
1159
1160 MMM Nth [YYYY]
1161 Nth MMM [YYYY]
1162 YYYY MMM Nth
1163 YYYY Nth MMM
1164 Dec 1st 1970
1165 1st Dec 1970
1166 1970 Dec 1st
1167 1970 1st Dec
1168
1169 next/prev DoW
1170 The next or last occurrence of DoW
1171 next Friday
1172 last Friday at 12:40
1173
1174 next/last week/month/year
1175 The day one week/month/year from now
1176 or in the past
1177 next week
1178 last month at 15:00
1179
1180 last day in MMM [YYYY]
1181 The last day of the month
1182 last day in October
1183 last day in October 1996
1184
1185 last DoW in MMM [YYYY]
1186 The last DoW in the month
1187 last Tuesday in October
1188 last Tuesday in October 1996
1189
1190 last DoW in YYYY
1191 The last DoW in the year
1192 last Tuesday in 1997
1193
1194 NOTE: "last DoW" doesn't work in
1195 English since the word "last"
1196 is used for both this expression
1197 and for "prev DoW", which gets
1198 parsed first. "last DoW" MAY
1199 work in other languages.
1200
1201 Nth DoW in MMM [YYYY]
1202 The Nth DoW in the month
1203 3rd Tuesday in October
1204 3rd Tuesday in October 1996
1205
1206 Nth DoW [YYYY]
1207 The Nth DoW in the year
1208 22nd Sunday
1209 22nd Sunday in 1996
1210
1211 Nth day in MMM [YYYY]
1212 The Nth day of the month
1213 1st day of February
1214 1st day of February 2012
1215
1216 DoW week
1217 British: same as "in 1 week on DoW"
1218 Monday week
1219
1220 DoW week N [YYYY]
1221 Dow Nth week [YYYY]
1222 Sunday week 22
1223 Sunday 22nd week
1224 These refer to the day of week
1225 of the Nth week of the year.
1226
1227 Nth
1228 12th
1229 This refers to the Nth day of the
1230 current month.
1231
1232 Note that the formats "Sunday week 22" and "22nd Sunday" give
1233 different behaviors. "Sunday week 22" returns the Sunday of the 22nd
1234 week of the year based on how week 1 is defined. ISO 8601 defines
1235 week one to contain Jan 4, so "Sunday week 1" might be the first or
1236 second Sunday of the current year, or the last Sunday of the previous
1237 year. "22nd Sunday" gives the actual 22nd time Sunday occurs in a
1238 given year, regardless of the definition of a week.
1239
1240 =item B<Special date strings>
1241
1242 Most languages have strings which can be used to specify the date (relative
1243 to today). In English, these include the strings:
1244
1245 today
1246 tomorrow
1247 yesterday
1248
1249 There is also support for the British formats:
1250
1251 today week
1252 tomorrow week
1253 yesterday week
1254
1255 which refer to one week after today/tomorrow/yesterday respectively.
1256
1257 Other languages have similar strings.
1258
1259 =item B<Holidays>
1260
1261 You can parse holiday names as dates (including timezones). For example:
1262
1263 Christmas
1264 Christmas 2010
1265 Christmas 2010 at noon
1266 Christmas 2010 at noon PST
1267 Saturday Christmas 2010 at noon
1268
1269 =back
1270
1271 In all of the formats (except for ISO 8601 formats), the day of week
1272 ("Friday") can be entered anywhere in the date and it will be checked
1273 for accuracy. In other words,
1274
1275 "Tue Jul 16 1996 13:17:00"
1276
1277 will work but
1278
1279 "Jul 16 1996 Wednesday 13:17:00"
1280
1281 will not (because Jul 16, 1996 is Tuesday, not Wednesday).
1282
1283 =head1 A NOTE ABOUT FOREIGN LANGUAGE DATES
1284
1285 Although Date::Manip has some support for parsing dates in foreign
1286 languages, it must be noted that the formats supported are largely
1287 based on English equivalents.
1288
1289 There are probably many different dates that are perfectly valid, and
1290 in common usage, in other languages which do not have an equivalent in
1291 the English language, and unfortunately, Date::Manip will probably not
1292 parse these.
1293
1294 You are free to send these to me, and I'll see if there is a way to
1295 add them in, but I do not guarantee anything. Without having a
1296 full-blown language parser (or at least the portion of the language
1297 that is devoted to calendar and time), most of these formats will
1298 simply not be supportable.
1299
1300 =head1 VALID TIME FORMATS
1301
1302 There are several categories of time formats supported by Date::Manip.
1303 These are strings which specify only the hour/minute/second fields.
1304
1305 =over 4
1306
1307 =item B<ISO 8601 times>
1308
1309 A time may be also be complete or truncated. Again, Date::Manip
1310 treats some formats as complete even though the specification calls
1311 them truncated.
1312
1313 A time may include the following fields:
1314
1315 HH 2-digit representation of the hour
1316 MN 2-digit representation of the minutes
1317 SS 2-digit representation of the seconds
1318 H+ 1+ digit representation of fractional hours
1319 M+ 1+ digit representation of fractional minutes
1320 S+ 1+ digit representation of fractional seconds
1321
1322 The following time formats are considered complete by Date::Manip. The time
1323 12:30:15 will be expressed in the examples.
1324
1325 Format Notes Examples
1326
1327 HHMNSS 2 123015
1328
1329 HH:MN:SS 12:30:15
1330
1331 HHMNSS,S+ 123015,5
1332 HH:MN:SS,S+ 12:30:15,5
1333 Fractional seconds are ignored
1334
1335 HHMN,M+ 1230,25
1336 HH:MN,M+ 12:30,25
1337 This is 12:30:00 + 0.25 minutes
1338
1339 HH,H+ 12,5
1340 This is 12:00:00 + 0.5 hours, so
1341 this is equivalent to 12:30:00
1342
1343 -MNSS 1 -3015
1344 -MN:SS -30:15
1345
1346 --SS 1 --15
1347
1348 -MNSS,S+ 1 -3015,5
1349 -MN:SS,S+ -30:15,5
1350
1351 -MN,M+ 1 -30,25
1352
1353 --SS,S+ 1 --15,5
1354
1355 HHMN 3 1230
1356 HH:MN 12:30
1357
1358 The following time formats are truncated:
1359
1360 HH 12
1361
1362 -MN -30
1363
1364 Notes:
1365
1366 1 These formats are considered truncated in the standard, but since
1367 they do include (or imply, using the current time for defaults) all of
1368 the fields, and since they do not introduce any parsing complexities,
1369 the standard is relaxed, and they are treated as complete.
1370
1371 2 The HHMNSS format will not be correctly parsed since it is impossible
1372 to distinguish between it and YYMMDD. In order to parse an all-digit
1373 time, add the string ",0" to the end to force it to be interpreted
1374 as a time or include time zone information (either a zone name or
1375 abbreviation... an offset will not work in this case).
1376
1377 3 The HH:MN format will be treated as complete, even though it is
1378 incomplete due to missing the seconds. In real life, expressing
1379 a time in the HH:MN format is very common, and is regarded as complete,
1380 and might include time zone information.
1381
1382 ISO 8601 times may be followed by a time zone unless they are truncated.
1383 Truncated times may not include a timezone. Date::Manip relaxes the
1384 constraints placed on the time zone format and allows any of the
1385 methods used to specify the time zone including time zone name, abbreviation,
1386 or offset. The time zone may be separated from the time by a space, but
1387 it is not required.
1388
1389 Another constraint that is relaxed is that the fractional part may be
1390 specified using a period. In other words, the following are equivalent:
1391
1392 12:30,25
1393 12:30.25
1394
1395 It should be noted (as it is in the specification) that using a
1396 negative time zone offset may cause confusion. In addition to visually
1397 confusing, it may not be parsed correctly. For example, the time:
1398
1399 123005-0300
1400
1401 may not be parsed correctly. When using an offset time zone, you
1402 should always use the colon separators in the time:
1403
1404 12:30:05-0300
1405
1406 =item B<Other time formats>
1407
1408 A time may include any of the following fields:
1409
1410 H24 1- or 2-digit representation of the hour (0-23)
1411 H12 1- or 2-digit representation of the hour (1-12)
1412 MN 2-digit representation of the minutes
1413 SS 2-digit representation of the seconds
1414 H+ 1+ digit representation of fractional hours
1415 M+ 1+ digit representation of fractional minutes
1416 S+ 1+ digit representation of fractional seconds
1417 AM A language specific AM/PM string
1418
1419 The following time formats are accepted:
1420
1421 Format Examples
1422
1423 H24:MN:SS 17:30:15
1424 H12:MN:SS AM 5:30:15 PM
1425 H12:MN:SS
1426
1427 H24:MN:SS,S+ 17:30:15,5
1428 H12:MN:SS,S+ AM 5:30:15,5 PM
1429 H12:MN:SS,S+ Fractional seconds are ignored
1430
1431 H24:MN,M+ 17:30,25
1432 H12:MN,M+ AM 5:30,25 PM
1433 H12:MN,M+ This is 17:30:00 + 0.25 minutes
1434
1435 H24,H+ 17,5
1436 H12,H+ AM 5,5 PM
1437 H12,H+ This is 17:00:00 + 0.5 hours, so
1438 this is equivalent to 17:30:00
1439
1440 H24:MN 17:30
1441 H12:MN AM 5:30 PM
1442 H12:MN
1443
1444 H12 AM 5 PM
1445
1446 The fractional part may be specified using a comma or a period.
1447 Fractional seconds may also be separated using a colon. A
1448 language specific fractional separator may also be available for
1449 some languages.
1450
1451 In other words, the following are equivalent:
1452
1453 12:30:20,25
1454 12:30:20.25
1455 12:30:20:25
1456
1457 Some languages have alternate H:MN and MN:S separators. For example,
1458 one H:MN separator in French is 'h' (the MN:S separator is still a
1459 colon), so the following are equivalent:
1460
1461 12:30:00
1462 12h30:00
1463
1464 Time zone information can be included immediately following the time.
1465 It can be separated by whitespace from the time, or it can be
1466 immediately adjacent.
1467
1468 =item B<Special time strings>
1469
1470 Different languages may have some words which can be used to specify a
1471 certain time of day. In English, for example, the following words are
1472 equivalent to the time listed:
1473
1474 noon 12:00:00
1475 midnight 00:00:00
1476
1477 So, the following are equivalent:
1478
1479 Jan 2 2009 at noon
1480 Jan 2 2009 12:00:00
1481
1482 There were two possible ways to interpret midnight. One was at the
1483 start of the day (00:00:00) and the other was at the end of the day
1484 (24:00:00 which would actually mean at 00:00:00 of the following day).
1485 The first has been used to maintain backwards compatibility with
1486 Date::Manip 5.xx .
1487
1488 Other languages have similar strings.
1489
1490 =back
1491
1492 In most languages, a word similar to "at" may precede the time (this
1493 does NOT apply to ISO 8601 time formats). This word (which must be
1494 separate from all other parts of the date with whitespace) is
1495 optional, and the following are equivalent:
1496
1497 12:30
1498 at 12:30
1499
1500 The times "12:00 am", "12:00 pm", and "midnight" are not well defined.
1501 Date::Manip uses the following convention:
1502
1503 midnight = 12:00am = 00:00:00
1504 noon = 12:00pm = 12:00:00
1505
1506 and the day goes from 00:00:00 to 23:59:59. In other words, midnight is the
1507 beginning of a day rather than the end of one. The time 24:00:00 is also
1508 allowed (though it is automatically transformed to 00:00:00 of the following
1509 day). This gives the unusual result of parsing:
1510
1511 Wed Feb 8 2006 24:00:00
1512
1513 which gives the date of:
1514
1515 Thu Feb 9 2006 00:00:00
1516
1517 =head1 VALID COMBINED DATE AND TIME FORMATS
1518
1519 There are several categories of strings which specify both the date and
1520 time. These include the following:
1521
1522 =over 4
1523
1524 =item B<ISO 8601 combined date and time>
1525
1526 A combined ISO 8601 date and time is a string containing a complete
1527 ISO 8601 date and a complete or truncated ISO 8601 time. It may
1528 also include a timezone, provided a complete time is included.
1529
1530 Date::Manip relaxes the restrictions on how the two are combined. The
1531 time may be separated from the date by space, dash, or the letter T,
1532 or the two may be joined with nothing separating them.
1533
1534 When the time immediately follows the date, or when the two are
1535 separated by a dash, the resulting string MUST be
1536 unambiguous. Provided the date includes all of the dashes in it
1537 (i.e. YY-MM-DD instead of YYMMDD), it is rare that there is any
1538 ambiguity. If the date does not include dashes, the strings may be
1539 ambiguous, and in this case, separating the date and time with a space
1540 or the letter T is useful (and perhaps necessary) to correctly
1541 interpret the string.
1542
1543 The DoY formats should always be separated from the time by
1544 something. They are visually confusing if they are not separated from
1545 the time.
1546
1547 Time zone information can be included immediately following a complete
1548 time. It may not be included if no time is given, or if a truncated
1549 time is included. The time zone may be separated from the time with
1550 whitespace, or it can be immediately adjacent to it (since the ISO
1551 8601 specification allows it in some cases).
1552
1553 =item B<Non-ISO 8601 combined date and time>
1554
1555 A date from any of the non-ISO 8601 formats above may be combined with
1556 any of the non-ISO 8601 time formats above in any combination to form
1557 a valid combined date and time.
1558
1559 =item B<Deltas>
1560
1561 Dates are often specified in terms of a delta from "now". For example,
1562 "in 2 days".
1563
1564 Most valid deltas can be used to specify a date, and the date is defined
1565 as that delta added to "now". Refer to the Date::Manip::Delta documentation
1566 for a list of valid delta formats.
1567
1568 If the delta itself does not include a time part, the time may be specified
1569 explicitly. For example:
1570
1571 in 3 days at 12:00:00
1572 in 3 days at 12:00:00 PST
1573
1574 will take the delta part "in 3 days" and add it to the current time, then
1575 set the time to 12:00:00.
1576
1577 It is NOT allowed to include an explicit time if any time segment was
1578 included in the delta. For example, the following is invalid:
1579
1580 in 3 days 2 hours at 12:00:00
1581
1582 One additional format that is supported is to include only week (or higher)
1583 components in the delta and to set the day of week. For example:
1584
1585 Friday in 2 weeks
1586 in 2 weeks on Friday
1587 Friday 2 weeks ago
1588 2 weeks ago on Friday at 13:45
1589
1590 These first apply the delta (of weeks, months, and years) to the current
1591 time, and then set the day to the given day-of-week in that week.
1592
1593 =item B<Special date and time strings>
1594
1595 Most language have strings which can be used to specify the full date and
1596 time (relative to the current date and time). In English, these include
1597 the string:
1598
1599 now
1600
1601 They may also have a timezone attached:
1602
1603 now PST
1604
1605 =item B<Additional combined date and time formats>
1606
1607 The following formats are also supported:
1608
1609 epoch SECS
1610 The number of seconds since the epoch
1611 (Jan 1, 1970 00:00:00 GMT). SECS may
1612 be negative to give time before the
1613 epoch.
1614
1615 or
1616
1617 epoch SECS TIMEZONE
1618
1619 =back
1620
1621 A couple of notes:
1622
1623 Commas may be included in all date formats arbitrarily (except for ISO
1624 8601 formats where they may only be included when allowed by the
1625 specification).
1626
1627 The time/time zone is removed from the date before the date is parsed,
1628 so the time may appear before or after the date, or between any two
1629 parts of the date.
1630
1631 The time and the zone do not need to be adjacent, so the string:
1632
1633 Jan 21 17:13:27 2010 -0400
1634
1635 will work. If the timezone is separate from the date, it MUST be
1636 separated from any other portion of the date by whitespace.
1637
1638 Certain words such as "on", "in", "at", "of", etc. which commonly
1639 appear in a date or time are ignored (except in ISO 8601 formats).
1640
1641 =head1 PRINTF DIRECTIVES
1642
1643 The following printf directives are replaced with information
1644 from the date. These all assume that the Use_POSIX_Printf config
1645 variable is unset. If it is set, refer to POSIX PRINTF DIRECTIVES
1646 section below.
1647
1648 Year
1649 %y year - 00 to 99
1650 %Y year - 0001 to 9999
1651
1652 Month, Week
1653 %m month of year - 01 to 12
1654 %f month of year - " 1" to "12"
1655 %b,%h month abbreviation - Jan to Dec
1656 %B month name - January to December
1657
1658 Day
1659 %j day of the year - 001 to 366
1660 %d day of month - 01 to 31
1661 %e day of month - " 1" to "31"
1662 %v weekday abbreviation - " S"," M"," T", ...
1663 %a weekday abbreviation - Sun to Sat
1664 %A weekday name - Sunday to Saturday
1665 %w day of week - 1 to 7 (1=Monday)
1666 %E day of month with
1667 suffix - 1st, 2nd, 3rd...
1668
1669 Hour
1670 %H hour - 00 to 23
1671 %k hour - " 0" to "23"
1672 %i hour - " 1" to "12"
1673 %I hour - 01 to 12
1674 %p AM or PM
1675
1676 Minute, Second, Time zone
1677 %M minute - 00 to 59
1678 %S second - 00 to 59
1679 %Z time zone abbreviation - EDT
1680 %z time zone as GMT offset - +0100 (see Note 4)
1681 %N time zone as GMT offset - +01:00:00
1682
1683 Epoch (see NOTE 3 below)
1684 %s seconds from
1685 1/1/1970 GMT - negative if before
1686 %o seconds from 1/1/1970
1687 in the current time
1688 zone
1689
1690 Date, Time
1691 %c %a %b %e %H:%M:%S %Y - Fri Apr 28 17:23:15 1995
1692 %C,%u %a %b %e %H:%M:%S %Z %Y - Fri Apr 28 17:25:57 EDT 1995
1693 %g %a, %d %b %Y %H:%M:%S %Z - Fri, 28 Apr 1995 17:23:15 EDT
1694 %D %m/%d/%y - 04/28/95
1695 %x %m/%d/%y or %d/%m/%y - 04/28/95 or 28/04/95
1696 (Depends on DateFormat variable)
1697 %l date in ls(1) format (see NOTE 1 below)
1698 %b %e %H:%M - Apr 28 17:23 (*)
1699 %b %e %Y - Apr 28 1993 (*)
1700 %r %I:%M:%S %p - 05:39:55 PM
1701 %R %H:%M - 17:40
1702 %T,%X %H:%M:%S - 17:40:58
1703 %V %m%d%H%M%y - 0428174095
1704 %Q %Y%m%d - 19961025
1705 %q %Y%m%d%H%M%S - 19961025174058
1706 %P %Y%m%d%H:%M:%S - 1996102517:40:58
1707 %O %Y-%m-%dT%H:%M:%S - 1996-10-25T17:40:58
1708 %F %A, %B %e, %Y - Sunday, January 1, 1996
1709 %K %Y-%j - 1997-045
1710
1711 Special Year/Week formats (see NOTE 2 below)
1712 %G year, Monday as first
1713 day of week - 0001 to 9999
1714 %W week of year, Monday
1715 as first day of week - 01 to 53
1716 %L year, Sunday as first
1717 day of week - 0001 to 9999
1718 %U week of year, Sunday
1719 as first day of week - 01 to 53
1720 %J %G-W%W-%w - 1997-W02-2
1721
1722 Other formats
1723 %n insert a newline character
1724 %t insert a tab character
1725 %% insert a `%' character
1726 %+ insert a `+' character
1727
1728 All other characters are currently unused, but may be used in the
1729 future. They currently insert the character following the %.
1730
1731 The following multi-character formats also exist:
1732
1733 Extended formats
1734 %<A=NUM> These returns the NUMth value of the %A, %a, and %v formats
1735 %<a=NUM> respectively. In English, that would yield:
1736 %<v=NUM> %<A=2> => Tuesday
1737 %<a=2> => Tue
1738 %<v=2> => T
1739 NUM must be in the range 1-7.
1740
1741 %<B=NUM> These return the NUMth value of the %B and %b formats
1742 %<b=NUM> respectively. In English, that would yield:
1743 %<B=2> => February
1744 %<b=2> => Feb
1745 NUM must be in the range 1-12 (or 01-12).
1746
1747 %<p=NUM> These return the NUMth value of the %p format. In
1748 English, that would yield:
1749 %<p=1> => AM
1750 %<p=2> => PM
1751 NUM must be in the range 1-2.
1752
1753 %<E=NUM> These return the NUMth value of the %E format. In
1754 English, that would yield:
1755 %<E=1> => 1st
1756 %<E=53> => 53rd
1757 NUM must be in the range 1-53.
1758
1759 If a lone percent is the final character in a format, it is ignored.
1760
1761 The formats used in this routine were originally based on date.pl (version
1762 3.2) by Terry McGonigal, as well as a couple taken from different versions
1763 of the Solaris date(1) command. Also, several have been added which are
1764 unique to Date::Manip.
1765
1766 NOTE 1:
1767
1768 The ls format (%l) applies to date within the past OR future 6 months!
1769 Any date that is before the date NOW - 6 months, or that is on or
1770 after the date NOW + 6 months will have the year printed out.
1771
1772 The later time must be on or after so that there is no ambiguity. If it
1773 is now 2000-06-06-12:00:00, then the date 1999-12-06-12:00:00 will be
1774 written as "Dec 6 12:00" but the date 2000-12-06-12:00:00 will be written
1775 as "Dec 6 2000".
1776
1777 NOTE 2:
1778
1779 The %U, %W, %L, %G, and %J formats are used to support the ISO-8601 format:
1780 YYYY-wWW-D. In this format, a date is written as a year, the week of the
1781 year, and the day of the week. Technically, the week may be considered to
1782 start on any day of the week, but Sunday and Monday are both common
1783 choices, so both are supported.
1784
1785 The %W and %G formats return the week-of-year and the year treating weeks
1786 as starting on Monday.
1787
1788 The %U and %L formats return the week-of-year and the year treating weeks
1789 as starting on Sunday.
1790
1791 Most of the time, the %L and %G formats returns the same value as the %Y
1792 format, but there is a problem with days occurring in the first or last week
1793 of the year.
1794
1795 The ISO-8601 representation of Jan 1, 1993 written in the YYYY-wWW-D format
1796 is actually 1992-W53-5. In other words, Jan 1 is treated as being in the
1797 last week of the preceding year. Depending on the year, days in the first
1798 week of a year may belong to the previous year, and days in the final week
1799 of a year may belong to the next year. The week is assigned to the year
1800 which has most of the days. For example, if the week starts on Sunday,
1801 then the last week of 2003 is 2003-12-28 to 2004-01-03. This week is
1802 assigned to 2003 since 4 of the days in it are in 2003 and only 3 of them
1803 are in 2004. The first week of 2004 starts on 2004-01-04.
1804
1805 The %U and %W formats return a week-of-year number from 01 to 53. %L and
1806 %G return the corresponding year, and to get this type of information,
1807 you should always use the (%W,%G) combination or (%U,%L) combination. %Y
1808 should not be used as it will yield incorrect results.
1809
1810 %J returns the full ISO-8601 format (%G-W%W-%w).
1811
1812 NOTE 3:
1813
1814 The %s and %o formats return negative values if the date is before
1815 the start of the epoch. Other Unix utilities would return an error, or
1816 a zero, so if you are going to use Date::Manip in conjunction with these,
1817 be sure to check for a negative value.
1818
1819 NOTE 4:
1820
1821 The %z format returns the offset in the RFC 822 specified format
1822 +0500 . Most offsets are full hour amounts, so this is not a problem,
1823 but some offsets are irregular (+05:17:30). In this case, the string
1824 returned is +051730 which isn't RFC 822 compliant, but since RFC 822
1825 ignores this situation, I had to decide between returning an incorrect
1826 value, or breaking strict compliance, and I chose the second option.
1827
1828 =head1 POSIX PRINTF DIRECTIVES
1829
1830 For various reasons, a few of the printf directives in the
1831 Date::Manip::Date::printf method do not match the standard POSIX
1832 strftime directives. For backward compatibility reasons, I'm not
1833 going to change that. However, the Use_POSIX_Printf config variable
1834 can be set to 1 to use the POSIX formats instead of the default
1835 formats.
1836
1837 When that variable is set, most of the printf formats described above
1838 are used, but the formats are replaced with their POSIX value:
1839
1840 %C The century number (first two digits of the year).
1841
1842 %F This is equivalent to %Y-%m-%d
1843
1844 %l The hour (12-hour clock) padded with spaces
1845
1846 %P Either 'am' or 'pm'.
1847
1848 %u Day of week from 1-7 with Monday being 1.
1849
1850 %G Similar to the %G format described above, but strictly adheres
1851 to the ISO 8601 week definition where the first week of
1852 the week is Monday and the first week of the year contains
1853 Jan 4.
1854
1855 %g Identical to %g but only has the last two digits of the year.
1856
1857 %W Similar to the %W format described above, but with Monday
1858 being the first day of the week and the first Monday in the
1859 year being the first day of the first week.
1860
1861 %V Similar to the %W format described above, but strictly adheres
1862 to the ISO 8601 week definition where the first week of
1863 the week is Monday and the first week of the year contains
1864 Jan 4.
1865
1866 %L The strftime function does not have a %L directive. I have
1867 set it anyway to be similar to the %L format above except
1868 using Sunday as the first day of the week and the first week
1869 of the year contains Jan 4 (so this is the equivalent of %G
1870 but with Sunday being the first day of the week).
1871
1872 %U Similar to the %U format described above but with Sunday being
1873 the first day of the week and the first Sunday being the first
1874 day of the first week.
1875
1876 %J The strftime function does not have a %J directive, but in
1877 order to support the ISO 8601 YYYY-wWW-D format, this is
1878 equivalent to '%G-W%V-%w'.
1879
1880 Note 1: The default (i.e. non-POSIX) Date::Manip printf formats are
1881 defined so that %G and %W use the exact same definition of week and
1882 likewise %L and %U use the same definition of weeks. This means that
1883 you can use them to write a date in an ISO 8601 YYYY-wWW format. In
1884 the POSIX strftime definitions, %G and %V work together, but there is
1885 no equivalent pair for Sunday being the first day of the week.
1886
1887 The following POSIX strftime directives are not yet supported (though
1888 they may be in a future version of Date::Manip). These will continue
1889 to return the values listed above from the non-POSIX formats.
1890
1891 %c, %x, %X
1892 The strftime format give the preferred date/time representations
1893 in the current locale.
1894
1895 Currently Date::Manip does not make use of locale information
1896 so there is no locale-specific format.
1897
1898 The default format (which is the preferred date and time
1899 format in America) is used in all locales.
1900
1901 %E, %O
1902 Modifiers to create additional directives.
1903
1904 %+ Date and time in the format of the date command
1905
1906 =head1 KNOWN BUGS
1907
1908 None known.
1909
1910 =head1 BUGS AND QUESTIONS
1911
1912 Please refer to the Date::Manip::Problems documentation for
1913 information on submitting bug reports or questions to the author.
1914
1915 =head1 SEE ALSO
1916
1917 Date::Manip - main module documentation
1918
1919 =head1 LICENSE
1920
1921 This script is free software; you can redistribute it and/or
1922 modify it under the same terms as Perl itself.
1923
1924 =head1 AUTHOR
1925
1926 Sullivan Beck (https://github.com/SBECK-github/)
1927
1928 =cut