1Date::Manip::Recur(3) User Contributed Perl DocumentationDate::Manip::Recur(3)
2
3
4

NAME

6       Date::Manip::Recur - methods for working with recurring events
7

SYNOPSIS

9          use Date::Manip::Recur;
10          $date = new Date::Manip::Recur;
11

DESCRIPTION

13       This module contains functions useful in parsing and manipulating
14       recurrences.  A recurrence is a notation for specifying when a
15       recurring event occurs.  For example, if an event occurs every other
16       Friday or every 4 hours, this can be defined as a recurrence. A fully
17       specified recurrence consists of the following pieces of information:
18
19       Frequency
20           The most basic piece of information is the frequency.  For
21           relatively simple recurring events, the frequency defines when
22           those events occur. For more complicated recurring events, the
23           frequency tells approximately when the events occur (but to get the
24           actual events, the modifiers must be applied as described below).
25
26           Examples include:
27
28              the first of every month
29              every other day
30              the 4th Thursday of each month at 2:00 PM
31              every 2 hours and 30 minutes
32
33           All of these can be expressed as a frequency.
34
35           NOTE: unlike date parsing, support for frequencies written out in
36           English (or whatever language you are working in) is extremely
37           limited. For example, the string "the first of every month" will
38           NOT be parsed as a valid frequency. A limited number of frequencies
39           can be expressed in a written out form (see OTHER FREQUENCY FORMATS
40           below), but most must be expressed in the format described below in
41           FREQUENCY NOTATION. In the documentation however, the written out
42           form will often be used for the sake of clarity.
43
44           Since a frequency typically refers to events could happen an
45           infinite number of times, you must specify either a date range or a
46           base date (or both) in order to determine actual dates on which an
47           event occurred.
48
49       Modifier
50           Complex recurring events may require the use of modifiers in order
51           to get them correct.
52
53           For example, in America many places treat both Thanksgiving and the
54           day after as holidays. Thanksgiving is easy to define as the
55           frequency:
56
57              4th Thursday of every November
58
59           but the day after is NOT possible to define only as a frequency.
60           Depending on the year, the day after the 4th Thursday may be the
61           4th or 5th Friday.
62
63           The day after Thanksgiving must be defined as a frequency and a
64           modifier:
65
66              4th Thursday of every November
67              +1 day
68
69           The syntax for the various modifiers is described below in the
70           MODIFIERS section.
71
72       Base date
73           All recurrences have a base date which is a date on which a
74           recurring event is based.
75
76           The base date is not necessarily a date where the recurring event
77           occurs. Instead, it may be modified (with modifiers, or with values
78           specified in the recurrence) to actually produce a recurring event.
79
80           For example, if the frequency is
81
82              every other Friday at noon
83
84           the base date will be a Friday and the recurring event will happen
85           on that Friday, Friday two weeks later, Friday four weeks later,
86           etc.  In all cases, the dates will be modified to be at noon.
87
88           If the frequency has a modifier, such as:
89
90              every other Friday
91              + 1 day
92
93           (and yes, this trivial example could be expressed as the frequency
94           'every other Saturday' with no modifiers), then the base date is
95           still on a Friday, but the actual recurring event is determined by
96           applying modifiers and occurs on Saturday.
97
98           Recurring events are assigned a number with the event that is
99           referred to by the base date being the 0th occurrence, the first
100           one after that as the 1st occurrence, etc.  Recurring events can
101           also occur before the base date with the last time the recurring
102           event occurred before the base date is the -1th occurence.
103
104           So, if the frequency is
105
106              the first of every month
107
108           and the base date is 'Mar 1, 2000', then the 5 recurring events
109           around it are:
110
111              N    Date
112
113              -2   Jan 1 2000
114              -1   Feb 1 2000
115               0   Mar 1 2000
116              +1   Apr 1 2000
117              +2   May 1 2000
118
119           In some cases, the Nth date may not be defined. For example, if the
120           frequency is:
121
122              the 31st of every month
123
124           and the base date is Mar 31, 2000, the 5 recurring events around it
125           are:
126
127              N   Date
128
129              -2  Jan 31 2000
130              -1  undefined
131               0  Mar 31 2000
132               1  undefined
133               2  May 31 2000
134
135           There are actually two different uses of the term 'base date' which
136           should be understood.
137
138           The first is the base date as specified by the programmer. The
139           second is the actual base date as used internally by Date::Manip.
140
141           The information in the base date specified by the programmer may
142           not actually refer to a date which matches the frequency. In this
143           case, the base date used by Date::Manip is based on the specified
144           base date, but is not identical to it.  For more details, refer to
145           the BASE DATES section below.
146
147           For example, with the frequence 'the first of every month', if the
148           specified base date is 'Mar 1, 2000', this refers to a date on
149           which the recurring event occurred, so the actual base date is the
150           same as the specified one.
151
152           If the specified base date were 'Feb 20, 2000', the actual base
153           date would be use the month (Feb) of the specified base date, but
154           not the day, and the actual base date would be 'Feb 1, 2000'.
155
156       Range
157           A date range is simply a starting and an ending date. When a range
158           is used (primarily in the dates method as described below), only
159           recurring events (with all modifiers applied) which happened on or
160           after the start date and on or before the end date are used.
161
162           For example, if the frequency was
163
164              the first of every month
165
166           and the start/end dates were Jan 1 2000 and May 31 2000, the list
167           of dates referred to would be:
168
169              Jan 1 2000
170              Feb 1 2000
171              Mar 1 2000
172              Apr 1 2000
173              May 1 2000
174
175           If no base date is specified, but a date range is specified, the
176           start date is used as the specified base date.
177
178           It should be noted that if both the range and base date are
179           specified, the range is not used to determine a base date. Also,
180           the first time the recurring event occurs in this range may NOT be
181           the 0th occurrence with respect to the base date, and that is
182           allowed.
183
184           NOTE: both dates in the range and the base date must all be in the
185           same time zone, and use the same Date::Manip::Base object.
186

FREQUENCY NOTATION

188       The syntax for specifying a frequency requires some explanation. It is
189       very concise, but contains the flexibility to express every single type
190       of recurring event I could think of.
191
192       The syntax of the frequency description is a colon separated list of
193       the format Y:M:W:D:H:MN:S (which stand for year, month, week, etc.).
194       One (and only one) of the colons may optionally be replaced by an
195       asterisk, or an asterisk may be prepended to the string.  For example,
196       the following are all valid frequency descriptions:
197
198         1:2:3:4:5:6:7
199         1:2*3:4:5:6:7
200        *1:2:3:4:5:6:7
201
202       But the following are NOT valid because they contain more than one
203       asterisk:
204
205         1:2*3:4:5*6:7
206        *1:2:3:4:5:6*7
207
208       When an asterisk is included, the portion to the left of it is called
209       the interval, and refers to an approximate time interval between
210       recurring events.  For example, if the interval of the frequency is:
211
212         1:2*
213
214       it means that the recurring event occurs approximately every 1 year and
215       2 months.  The interval is approximate because elements to the right of
216       the asterisk, as well as any modifiers included in the recurrence, will
217       affect when the events actually occur.
218
219       If no asterisks are included, then the entire recurrence is an
220       interval.  For example,
221
222         0:0:0:1:12:0:0
223
224       refers to an event that occurs every 1 day, 12 hours.
225
226       The portion of the frequency that occur after an asterisk is called the
227       recurrence time (or rtime), and refers to a specific value (or values)
228       for that type of time element (i.e. exactly as it would appear on a
229       calendar or a clock).  For example, if the frequency ends with the
230       rtime:
231
232         *12:0:0
233
234       then the recurring event occurs at 12:00:00 (noon).
235
236       For example:
237
238         0:0:0:2*12:30:0      every 2 days at 12:30 (each day)
239
240       Elements in the rtime can be listed as single values, ranges (2 numbers
241       separated by a dash "-"), or a comma separated list of values or
242       ranges.  In some cases, negative values are appropriate for the week or
243       day values. -1 stands for the last possible value, -2 for the second to
244       the last, etc.
245
246       If multiple values are included in more than one field in the rtime,
247       every possible combination will be used. For example, if the frequency
248       ends with the rtime:
249
250         *12-13:0,30:0
251
252       the event will occur at 12:00, 12:30, 13:00, and 13:30.
253
254       Some examples are:
255
256         0:0:0:1*2,4,6:0:0    every day at at 02:00, 04:00, and 06:00
257         0:0:0:2*12-13:0,30:0 every other day at 12:00, 12:30, 13:00,
258                              and 13:30
259         0:1:0*-1:0:0:0       the last day of every month
260         *1990-1995:12:0:1:0:0:0
261                              Dec 1 in 1990 through 1995
262
263       There is no way to express the following with a single recurrence:
264
265         every day at 12:30 and 1:00
266
267       You have to use two recurrences to do this.
268
269       You can include negative numbers in ranges. For example, including the
270       range -2---1 means to go from the 2nd to the last to the last
271       occurrence.  Negative values are only supported in the week and day
272       fields, and only in some cases.
273
274       You can even use a range like 2--2 (which means to go from the 2nd to
275       the 2nd to the last occurrence). However, this is STRONGLY discouraged
276       since this leads to a date which produces a variable number of events.
277       As a result, the only way to determine the Nth date is to calculate
278       every date starting at the base date. If you know that every date
279       produces exactly 4 recurring events, you can calculate the Nth date
280       without needing to determine every intermediate date.
281
282       When specifying a range, the first value must be less than the second
283       or else nothing will be returned.
284
285       When both the week and day elements are non-zero and the day is right
286       of the asterisk, the day refers to the day of week. The following
287       examples illustrate these type of frequencies:
288
289         0:1*4:2:0:0:0        4th Tuesday (day 2) of every month
290         0:1*-1:2:0:0:0       last Tuesday of every month
291         0:0:3*2:0:0:0        every 3rd Tuesday (every 3 weeks
292                              on 2nd day of week)
293         1:0*12:2:0:0:0       the 12th Tuesday of each year
294
295       NOTE: The day of week refers to the numeric value of each day as
296       specified by ISO 8601. In other words, day 1 is ALWAY Monday, day 7 is
297       ALWAYS Sunday, etc., regardless of what day of the week the week is
298       defined to begin on (using the FirstDay config variable). So when the
299       day field refers to the day of week, it's value (or values if a range
300       or comma separated list are used) must be 1-7.
301
302       When the week element is zero and the month element is non-zero and the
303       day element is right of the asterisk, the day value is the day of the
304       month (it can be from 1 to 31 or -1 to -31 counting from the end of the
305       month).
306
307         3*1:0:2:12:0:0       every 3 years on Jan 2 at noon
308         0:1*0:2:12,14:0:0    2nd of every month at 12:00 and 14:00
309         0:1:0*-2:0:0:0       2nd to last day of every month
310
311       NOTE: If the day given refers to the 29th, 30th, or 31st, in a month
312       that does not have that number of days, it is ignored. For example, if
313       you ask for the 31st of every month, it will return dates in Jan, Mar,
314       May, Jul, etc.  Months with fewer than 31 days will be ignored.
315
316       If both the month and week elements are zero, and the year element is
317       non-zero, the day value is the day of the year (1 to 365 or 366 -- or
318       the negative numbers to count backwards from the end of the year).
319
320         1:0:0*45:0:0:0       45th day of every year
321
322       Specifying a day that doesn't occur in that year silently ignores that
323       year. The only result of this is that specifying +366 or -366 will
324       ignore all years except leap years.
325
326       If the week element is non-zero and to the right of the asterisk, and
327       the day element is zero, the frequency refers to the first day of the
328       given week of the month or week of the year:
329
330         0:1*2:0:0:0:0        the first day of the 2nd week of
331                              every month
332         1:0*2:0:0:0:0        the first day of the 2nd week of
333                              every year
334
335       Although the meaning of almost every recurrence can be deduced by the
336       above rules, a set of tables describing every possible combination of
337       Y/M/W/D meanings, and giving an example of each is included below in
338       the section LIST OF Y/M/W/D FREQUENCY DEFINITIONS. It also explains a
339       small number of special cases.
340
341       NOTE: If all fields left of the asterisk are zero, the last one is
342       implied to be 1. In other words, the following are equivalent:
343
344          0:0:0*x:x:x:x
345          0:0:1*x:x:x:x
346
347       and can be thought of as every possible occurence of the rtime.
348
349       NOTE: When applying a frequency to get a list of dates on which a
350       recurring event occurs, a delta is created from the frequency which is
351       applied to get dates referred to by the interval. These are then
352       operated on by the rtime and by modifiers to actually get the recurring
353       events.  The deltas will always be exact or approximate.  There is no
354       support for business mode recurrences. However, with the careful use of
355       modifiers (discussed below), most recurring business events can be
356       determined too.
357

BASE DATES

359       A recurrence of the form *Y:M:W:D:H:MN:S (which is technically speaking
360       not a recurring event... it is just a date or dates specified using the
361       recurrence syntax) uses the first date which matches the frequency as
362       the base date. Any base date specified will be completely ignored. A
363       date range may be specified to work with a subset of the dates.
364
365       All other recurrences use a specified base date in order to determine
366       when the 0th occurrence of a recurring event happens. As mentioned
367       above, the specified base date may be determined from the start date,
368       or specified explicitly.
369
370       The specified base date is used to provide the bare minimum
371       information. For example, the recurrence:
372
373          0:0:3*4:0:0:0       every 3 weeks on Thursday
374
375       requires a base date to determine the week, but nothing else. Using the
376       standard definition (Monday-Sunday) for a week, and given that one week
377       in August 2009 is Aug 10 to Aug 16, any date in the range Aug 10 to Aug
378       16 will give the same results. The definition of the week defaults to
379       Monday-Sunday, but may be modified using the FirstDay config variable.
380
381       Likewise, the recurrence:
382
383         1:3*0:4:0:0:0        every 1 year, 3 months on the 4th
384                              day of the month
385
386       would only use the year and month of the base date, so all dates in a
387       given month would give the same set of recurring dates.
388
389       It should also be noted that a date may actually produce multiple
390       recurring events. For example, the recurrence:
391
392          0:0:2*4:12,14:0:0   every 2 weeks on Thursday at 12:00
393                              and 14:00
394
395       produces 2 events for every date. So in this case, the base date
396       produces the 0th and 1st event, the base date + an offset produces the
397       2nd and 3rd events, etc.
398
399       It must be noted that the base date refers ONLY to the interval part of
400       the recurrence. The rtime and modifiers are NOT used in determining the
401       base date.
402

INTERVAL

404       The interval of a frequency (everything left of the asterisk) will be
405       used to generate a list of dates (called interval dates). When rtime
406       values and modifiers are applied to an interval date, it produces the
407       actual recurring events.
408
409       As already noted, if the rtime values include multiple values for any
410       field, more than one event are produced by a single interval date.
411
412       It is important to understand is how the interval dates are calculated.
413       The interval is trivially turned into a delta. For example, with the
414       frequency 0:0:2*4:12:0:0, the interval is 0:0:2 which produces the
415       delta 0:0:2:0:0:0:0.
416
417       In order to get the Nth interval date, the delta is multiplied by N and
418       added to the base date. In other words:
419
420          D(0) = Jan 31
421          D(1) = Jan 31 + 1 month = Feb 28
422          D(2) = Jan 31 + 2 month = Mar 31
423

DATE RANGE

425       The start and end dates form the range in which recurring events can
426       fall into.
427
428       Every recurring date will fall in the limit:
429
430          start <= date <= end
431
432       When a recurrence is created, it may include a default range, and this
433       is handled by the RecurRange config variable.
434

OTHER FREQUENCY FORMATS

436       There are a small handful of English strings (or the equivalent in
437       other languages) which can be parsed in place of a numerical frequency.
438       These include:
439
440         every Tuesday in June [1997]
441         2nd Tuesday in June [1997]
442         last Tuesday in June [1997]
443
444         every Tuesday of every month [in 1997]
445         2nd Tuesday of every month [in 1997]
446         last Tuesday of every month [in 1997]
447
448         every day of every month [in 1997]
449         2nd day of every month [in 1997]
450         last day of every month [in 1997]
451
452         every day [in 1997]
453         every 2nd day [in 1977]
454         every 2 days [in 1977]
455
456       Each of these set the frequency. If the year is include in the string,
457       it also sets the dates in the range to be the first and last day of the
458       year.
459
460       In each of these, the numerical part (i.e. 2nd in all of the examples
461       above) can be any number from 1 to 31. To make a frequency with a
462       larger number than that, you have to use the standard format discussed
463       above.
464
465       Due to the complexity of writing out (and parsing) frequencies written
466       out, I do not intend to add additional frequency formats, and the use
467       of these is discouraged. The frequency format described above is
468       preferred.
469

MODIFIERS

471       Any number of modifiers may be added to a frequency to get the actual
472       date of a recurring event.  Modifiers are case sensitive.
473
474       Modifiers to set the day-of-week
475           The following modifiers can be used to adjust a date to a specific
476           day of the week.
477
478             PDn   Means the previous day n not counting today
479             PTn   Means the previous day n counting today
480             NDn   Means the next day n not counting today
481             NTn   Means the next day n counting today
482
483           In each of these, 'n' is 1-7 (1 being Sunday, 7 being Saturday).
484
485           For example, PD2/ND2 returns the previous/next Tuesday. If the date
486           that this is applied to is Tuesday, it modifies it to one week in
487           the past/future.
488
489           PT2/NT2 are similar, but will leave the date unmodified if it is a
490           Tuesday.
491
492       Modifiers to move forward/backward a number of days
493           These modifiers can be used to add/subtract n days to a date.
494
495             FDn   Means step forward n days.
496             BDn   Means step backward n days.
497
498       Modifiers to force events to be on business days
499           Modifiers can also be used to force recurring events to occur on
500           business days. These modifiers include:
501
502             FWn   Means step forward n workdays.
503             BWn   Means step backward n workdays.
504
505             CWD   The closest work day (using the TomorrowFirst
506                   config variable).
507             CWN   The closest work day (looking forward first).
508             CWP   The closest work day (looking backward first).
509
510             NWD   The next work day counting today
511             PWD   The previous work day counting today
512             DWD   The closest work day (using the TomorrowFirst config
513                   variable) counting today
514
515           The CWD, CWN, and CWP modifiers will always change the date to the
516           closest working day NOT counting the current date.
517
518           The NWD, PWD, and DWD modifiers always change the date to the
519           closest working day unless the current date is a work day. In that
520           case, it is left unmodified.
521
522           CWD, CWN, and CWP will usually return the same value, but if you
523           are starting at the middle day of a 3-day weekend (for example), it
524           will return either the first work day of the following week, or the
525           last work day of the previous week depending on whether it looks
526           forward or backward first.
527
528           All business day modifiers ignore the time, so if a date is
529           initially calculated at Saturday at noon, and the FW1 is applied,
530           the date is initially moved to the following Monday (assuming it is
531           a work day) and the FW1 moves it to Tuesday. The final result will
532           be Tuesday at noon.
533
534       Special modifiers
535           The following modifiers do things that cannot be expressed using
536           any other combination of frequency and modifiers:
537
538             EASTER   Set the date to Easter for this year.
539

DETERMINING DATES

541       In order to get a list of dates referred to by the recurrence, the
542       following steps are taken.
543
544       The recurrence is tested for errors
545           The recurrence must be completely specified with a base date
546           (either supplied explicitly, or derived from a start date) and date
547           range when necessary. All dates must be valid.
548
549       The actual base date is determined
550           Using information from the interval and the specified base date,
551           the actual base date is determined.
552
553       The Nth date is calculated
554           By applying the delta that corresponds to the interval, and then
555           applying rtime and modifier information, the Nth date is
556           determined.
557
558           This is repeated until all desired dates have been obtained.
559
560           The nth method described below has more details.
561
562       The range is tested
563           Any date that fall outside the range is discarded.
564
565           NOTE: when the recurrence contains no interval, it is not necessary
566           to specify the range, and if it is not specified, all of the dates
567           are used. The range MAY be specified to return only a subset of the
568           dates if desired.
569

LIST OF Y/M/W/D FREQUENCY DEFINITIONS

571       Because the week and day values may have multiple meanings depending on
572       where the asterisk is, and which of the fields have non-zero values, a
573       list of every possible combination is included here (though most can be
574       determined using the rules above).
575
576       When the asterisk occurs before the day element, and the day element is
577       non-zero, the day element can take on multiple meanings depending on
578       where the asterisk occurs, and which leading elements (year, month,
579       week) have non-zero values. It can refer to the day of the week, day of
580       the month, or day of the year.
581
582       When the asterisk occurs before the week element, the week element of
583       the frequency can also take on multiple meanings as well. When the
584       month field and day fields are zero, it refers to the week of the year.
585       Since the week of the year is well defined in the ISO 8601 spec, there
586       is no ambiguity.
587
588       When the month field is zero, but the day field is not, the week field
589       refers to the nth occurrence of the day of week referred to by the day
590       field in the year.
591
592       When the month field is non-zero, the week field refers to the nth
593       occurrence of the day of week in the month.
594
595       In the tables below only the first 4 elements of the frequency are
596       shown. The actual frequency will include the hour, minute, and second
597       elements in addition to the ones shown.
598
599       When all elements left of the asterisk are 0, the interval is such that
600       it occurs the maximum times possible (without changing the type of
601       elements to the right of the asterisk). Another way of looking at it is
602       that the last 0 element of the interval is changed to 1. So, the
603       interval:
604
605         0:0*3:0
606
607       is equivalent to
608
609         0:1*3:0
610
611       When the year field is zero, and is right of the asterisk, it means the
612       current year.
613
614       All elements left of the asterisk
615           When all of the month, week, and day elements are left of the
616           asterisk, the simple definitions of the frequency are used:
617
618             frequency     meaning
619
620             1:2:3:4       every 1 year, 2 months, 3 weeks,
621                           4 days
622
623           Any, or all of the fields can be zero.
624
625       Non-zero day, non-zero week
626           When both the day and week elements are non-zero, the day element
627           always refers to the day of week. Values must be in the range (1 to
628           7) and no negative values are allowed.
629
630           The following tables shows all possible variations of the frequency
631           where this can happen (where day 4 = Thursday).
632
633           When the week is left of the asterisk, the interval is used to get
634           the weeks on the calendar containing a recurring date, and the day
635           is used to set the day of the week.  The following are possible:
636
637             frequency     meaning
638
639             1:2:3*4       every 1 year, 2 months, 3 weeks
640                           on Thur
641
642             1:0:3*4       every 1 year, 3 weeks on Thur
643
644             0:2:3*4       every 2 months, 3 weeks on Thur
645
646             0:0:3*4       every 3 weeks on Thur
647
648           When the week is right of the asterisk, and a non-zero month is
649           left of the asterisk, the recurrence refers to a specific
650           occurrence of a day-of-week during a month. The following are
651           possible:
652
653             frequency     meaning
654
655             1:2*3:4       every 1 year, 2 months on the
656                           3rd Thursday of the month
657
658             0:2*3:4       every 2 months on the 3rd Thur
659                           of the month
660
661           When the week and month are both non-zero and right of the
662           asterisk, the recurrence refers to an occurrence of day-of-week
663           during the given month.  Possibilities are:
664
665             frequency     meaning
666
667             1*2:3:4       every 1 year in February on
668                           the 3rd Thur
669
670             0*2:3:4       same as 1*2:3:4
671
672            *1:2:3:4       in Feb 0001 on the 3rd Thur
673                           of the month
674
675            *0:2:3:4       on the 3rd Thur of Feb in the
676                           current year
677
678           When the week is right of the asterisk, and the month is zero, the
679           recurrence refers to an occurence of the day-of-week during the
680           year. The following are possible:
681
682             frequency     meaning
683
684             1:0*3:4       every 1 year on the 3rd Thursday
685             1*0:3:4       of the year
686
687            *1:0:3:4       in 0001 on the 3rd Thur of
688                           the year
689
690             0*0:3:4       same as 1*0:3:4
691
692            *0:0:3:4       on the 3rd Thur of the current
693                           year
694
695           There is one special case:
696
697             frequency     meaning
698
699             0:0*3:4       same as 0:1*3:4 (every month on
700                           the 3rd Thur of the month)
701
702       Non-zero day, non-zero month
703           When a non-zero day element occurs to the right of the asterisk and
704           the week element is zero, but the month element is non-zero, the
705           day elements always refers to a the day of month in the range (1 to
706           31) or (-1 to -31).
707
708           The following table shows all possible variations of the frequency
709           where this can happen:
710
711             frequency     meaning
712
713             1:2:0*4       every 1 year, 2 months on the
714             1:2*0:4       4th day of the month
715
716             1*2:0:4       every year on Feb 4th
717
718            *1:2:0:4       Feb 4th, 0001
719
720             0:2:0*4       every 2 months on the 4th day
721             0:2*0:4       of the month
722
723             0*2:0:4       same as 1*2:0:4
724
725            *0:2:0:4       Feb 4th of the current year
726
727       Zero day, non-zero week
728           When a day is zero, and the week is non-zero, the recurrence refers
729           to a specific occurrence of the first day of the week (as given by
730           the FirstDay variable).
731
732           The frequency can refer to an occurrence of FirstDay in a specific
733           week (if the week is left of the asterisk):
734
735             frequency     meaning
736
737             1:2:3*0       every 1 year, 2 months, 3 weeks on
738                           FirstDay
739
740             1:0:3*0       every 1 year, 3 weeks on FirstDay
741
742             0:2:3*0       every 2 months, 3 weeks on FirstDay
743
744             0:0:3*0       every 3 weeks on FirstDay
745
746           or to a week in the year (if the week is right of the asterisk, and
747           the month is zero):
748
749             frequency     meaning
750
751             1:0*3:0       every 1 year on the first day of the
752             1*0:3:0       3rd week of the year
753
754            *1:0:3:0       the first day of the 3rd week of 0001
755
756           or to an occurrence of FirstDay in a month (if the week is right of
757           the asterisk and month is non-zero):
758
759             frequency     meaning
760
761             1:2*3:0       every 1 year, 2 months on the 3rd
762                           occurence of FirstDay
763
764             0:2*3:0       every 2 months on the 3rd occurence
765                           of FirstDay
766
767             1*2:3:0       every year on the 3rd occurence
768                           of FirstDay in Feb
769
770             0*2:3:0       same as 1*2:3:0
771
772            *1:2:3:0       the 3rd occurence of FirstDay
773                           Feb 0001
774
775            *0:2:3:0       the 3rd occurence of FirstDay
776                           in Feb of the current year
777
778           NOTE: in the last group, a slightly more intuitive definition of
779           these would have been to say that the week field refers to the week
780           of the month, but given the ISO 8601 manner of defining when weeks
781           start, this definition would have virtually no practical
782           application. So the definition of the week field referring to the
783           Nth occurence of FirstDay in a month was used instead.
784
785           There are a few special cases here:
786
787             frequency     meaning
788
789             0:0*3:0       same as 0:1*3:0   (every month on the 3rd
790                           occurence of the first day of week)
791
792             0*0:3:0       same as 1*0:3:0
793
794            *0:0:3:0       the first day of the 3rd week of the
795                           current year
796
797       Non-zero day
798           When a non-zero day element occurs and both the month and week
799           elements are zero, the day elements always refers to a the day of
800           year (1 to 366 or -1 to -366 to count from the end).
801
802           The following table shows all possible variations of the frequency
803           where this can happen:
804
805             frequency     meaning
806
807             1:0:0*4       every year on the 4th day of
808             1:0*0:4       the year
809             1*0:0:4
810
811            *1:0:0:4       the 4th day of 0001
812
813           Other non-zero day variations have multiple meanings for the day
814           element:
815
816             frequency     meaning
817
818             0:0:0*4       same as 0:0:1*4  (every week on Thur)
819
820             0:0*0:4       same as 0:1*0:4  (every month on the 4th)
821
822             0*0:0:4       same as 1*0:0:4
823
824            *0:0:0:4       the 4th day of the current year
825
826       All other variations
827           The remaining variations have zero values for both week and day.
828           They are:
829
830             frequency     meaning
831
832             1:2:0*0       every 1 year, 2 months on the first
833             1:2*0:0       day of the month
834
835             1*2:0:0       every year on Feb 1
836
837            *1:2:0:0       Feb 1, 0001
838
839             1:0:0*0       every 1 year on Jan 1
840             1:0*0:0
841             1*0:0:0
842
843            *1:0:0:0       Jan 1, 0001
844
845             0:2:0*0       every 2 months on the first day of
846             0:2*0:0       the month
847
848             0*2:0:0       same as 1*2:0:0
849
850            *0:2:0:0       Feb 1 of the current year
851
852             0:0:0*0       same as 0:0:1*0 (every week on
853                           the first day of the week)
854
855             0:0*0:0       same as 0:1*0:0 (every month
856                           on the 1st)
857
858             0*0:0:0       same as 1*0:0:0
859
860            *0:0:0:0       Jan 1 of the current year
861

METHODS

863       new
864       new_config
865       new_date
866       new_delta
867       new_recur
868       base
869       tz
870       is_date
871       is_delta
872       is_recur
873       config
874       err Please refer to the Date::Manip::Obj documentation for these
875           methods.
876
877       parse
878              $err = $recur->parse($string [,$modifiers] [,$base,$start,$end]);
879
880           This creates a new recurrence. A string containing a valid
881           frequency is required. In addition, $start, $end, and $base dates
882           can be passed in (either as Date::Manip::Date objects, or as
883           strings containing dates that can be parsed), and any number of the
884           modifiers listed above.
885
886           If the $start or $end dates are not included, they may be supplied
887           automatically, based on the value of the RecurRange variable. If
888           any of the dates are passed in, they must be included in the order
889           given (though it is safe to pass an empty string or undef in for
890           any of them if you only want to set some, but not all of them).
891
892           The $modifiers argument must either contain valid modifiers, or be
893           left out of the argument list entirely. You cannot pass an empty
894           string or undef in for it.
895
896              $err = $recur->parse($string);
897
898           This creates a recurrence from a string which contains all of the
899           necessary elements of the recurrence. The string is of the format:
900
901              FREQ*MODIFIERS*BASE*START*END
902
903           where FREQ is a string containing a frequency, MODIFIERS is a
904           string containing a comma separated list of modifiers, BASE, START,
905           and END are strings containing parseable dates.
906
907           All pieces are optional, but order must be maintained, so all of
908           the following are valid:
909
910              FREQ*MODIFIERS
911              FREQ**BASE
912              FREQ**BASE*START*END
913
914           If a part of the recurrence is passed in both as part of $string
915           and as an argument, the argument overrides the string portion, with
916           the possible exception of modifiers. The modifiers in the argument
917           override the string version unless the first one is a '+' in which
918           case they are appended. See the modifiers method below for more
919           information.
920
921       frequency
922       start
923       end
924       basedate
925       modifiers
926           You can also create a recurrency in steps (or replace parts of an
927           existing recurrence) using the following:
928
929              $err = $recur->frequency($frequency);
930
931              $err = $recur->start($start);
932              $err = $recur->end($end);
933
934              $err = $recur->basedate($base);
935
936              $err = $recur->modifiers($modifiers);
937              $err = $recur->modifiers(@modifiers);
938
939           These set the appropriate part of the recurrence.
940
941           Calling the frequency method discards all information currently
942           stored in the Recur object (including an existing start, end, and
943           base date), so this method should be called first.
944
945           In the modifiers method, the modifiers can be passed in as a string
946           containing a comma separated list of modifiers, or as a list of
947           modifiers. The modifiers passed in override all previously set
948           modifiers UNLESS the first one is the string "+", in which case the
949           new modifiers are appended to the list.
950
951           In the start, end, and base methods, the date passed in can be a
952           Date::Manip::Date object, or a string that can be parsed to get a
953           date.
954
955           NOTE: the parse method will overwrite all parts of the recurrence,
956           so it is not appropriate to do:
957
958              $recur->modifiers($modifiers);
959              $recur->parse($string);
960
961           The modifiers passed in in the first call will be overwritten.
962
963           These functions can also be used to look up the values.
964
965              $freq  = $recur->frequency();
966              $start = $recur->start();
967              $end   = $recur->end();
968              @mods  = $recur->modifiers();
969
970              ($base,$actual) = $recur->basedate();
971
972           The basedate function will return both the specified base and the
973           actual base dates.
974
975           If any of the values are not yet determined, nothing will be
976           returned.
977
978       dates
979              @dates = $recur->dates([$start,$end]);
980
981           Returns the list of dates defined by the full recurrence. If there
982           is an error, or if there are no dates, an empty list will be
983           returned.
984
985           $start and $end are either undef, or dates which can be used to
986           limit the set of dates passed back (they can be Date::Manip::Date
987           objects or strings that can be parsed).
988
989           If the recurrence does not have a start and end date already,
990           passing in $start and $end will set the range (but they will NOT be
991           stored in the recurrence).
992
993           If the recurrence does have a start and end date stored in it, the
994           $start and $end arguments can be used to temporarily override the
995           limits. For example, if a recurrence has a start date of Jan 1,
996           2006 00:00:00 and and end date of Dec 31, 2006 23:59:59 stored in
997           the recurrence, passing in $start of Jul 1, 2006 00:00:00 will
998           limit the dates returned to the range of Jul 1 to Dec 31.
999
1000           Passing in a start date of Jul 1, 2007 will mean that no dates are
1001           returned since the recurrence limits the date to be in 2006.
1002
1003           If one or both of $start and $end are undef, then the stored values
1004           will be used.
1005
1006       nth
1007              ($date,$err) = $recur->nth($n);
1008
1009           This returns the $n'th recurring event ($n may be any integer). If
1010           an error occurs, it is returned (but it is not set in $recur since
1011           it may be properly, though perhaps incompletely, defined). The
1012           following errors may be returned:
1013
1014              Invalid recurrence
1015                 The recurrence has an error flag set.
1016
1017              Incomplete recurrence
1018                 The recurrence is incomplete. It needs either a
1019                 base date or a date range.
1020
1021              Range invalid
1022                 The recurrence has an invalid date range (i.e.
1023                 the end date occurs before the start date).
1024
1025              Start invalid
1026              End invalid
1027              Base invalid
1028                 An invalid date was entered for one of the dates.
1029
1030           There are a few special circumstances to be aware of.
1031
1032           1) If the recurrence contains no interval (i.e. is of the form
1033           *Y:M:W:D:H:MN:S), the dates come directly from the rtime values.
1034           In this case, the 0th event is the first date in the list of dates
1035           specified by the rtime. As such, $n must be a positive integer.  If
1036           $n is negative, or outside the range of dates specified, the
1037           returned date will be undef (but this is not an error).
1038
1039           2) A very small number of recurrences have an unknown number of
1040           recurring events associated with each date.  This only happens if
1041           one of the values in the rtime is specified as a range including
1042           both a positive and negative index.  For example, if the day field
1043           in an rtime refers to the day of month, and is 15--15 (i.e. the
1044           15th day to the 15th to the last day), this may include 3 events
1045           (on a month with 31 days), 2 event (months with 30 days), 1 event
1046           (months with 29 days), or 0 events (months with 28 days). As such,
1047           in order to calculate the Nth date, you have to start with the 0th
1048           (i.e. base) date and calculate every event until you get the Nth
1049           one. For this reason, it is highly recommended that this type of
1050           frequency be avoided as it will be quite slow.
1051
1052           3) Most recurrences have a known number of events (equal to the
1053           number of combinations of values in the rtime) for each date. For
1054           these, calculating the Nth date is much faster. However, in this
1055           case, some of them may refer to an invalid date. For example, if
1056           the frequency is 'the 31st of every month' and the base (0th) date
1057           is Jan 31, the 1st event would refer to Feb 31. Since that isn't
1058           valid, undef would be returned for $n=1. Obviously, it would be
1059           possible to actually determine the Nth valid event by calculating
1060           all N-1 dates, but in the interest of performance, this is not
1061           done.
1062
1063           4) The way the Nth recurring event is calculated differs slightly
1064           for NE>0 and N<0 if the delta referred to by the frequency is
1065           approximate. To calculate the Nth recurring event (where N>0), you
1066           take the base date and add N*DELTA (where DELTA is the delta
1067           determined by the frequency).  To get the Nth recurring event
1068           (where N<0), a date is determine which, if N*DELTA were added to
1069           it, would produce the base date. For more details, refer to the
1070           Date::Manip::Calc document.  In the SUBTRACTION section in the
1071           discussion of approximate date-delta calculations, calculations are
1072           done with $subtract = 2.
1073
1074       next
1075       prev
1076              ($date,$err) = $recur->next();
1077              ($date,$err) = $recur->prev();
1078
1079           These return the next/previous recurring event.
1080
1081           The first time next/prev is called, one of the recurring events
1082           will be selected and returned (using the rules discussed below).
1083           Subsequent calls to next/prev will return the next or previous
1084           event.
1085
1086           Unlike the nth method which will return a specific event (or undef
1087           if the Nth even is not defined), the next and prev methods will
1088           only work with defined events.
1089
1090           So, for the recurrence:
1091
1092              the 31st of every month
1093
1094           next might return the following sequence of events:
1095
1096              Jan 31 2000
1097              Mar 31 2000
1098              May 31 2000
1099
1100           The rules for determining what event to return the first time one
1101           of these is called are as follows:
1102
1103           1) If there is a range, next will return the first event that
1104           occurs after the start of the range.  prev will return the last
1105           event that occurs before the end of the range.
1106
1107           2) If there is no range, next will return the first event on or
1108           after the base date.  prev will return the last event before the
1109           base date.
1110
1111           The error codes are the same as for the nth method.
1112

HISTORY OF THE FREQUENCY NOTATION

1114       I realize that the frequency notation described above looks quite
1115       complicated at first glance, but it is (IMO) the best notation for
1116       expressing recurring events in existence. I actually consider it the
1117       single most important contribution to date/time handling in
1118       Date::Manip.
1119
1120       When I first decided to add recurring events to Date::Manip, I first
1121       came up with a list of common ways of specifying recurring events, and
1122       then went looking for a notation that could be used to define them.  I
1123       was hoping for a notation that would be similar to cron notation, but
1124       more powerful.
1125
1126       After looking in several specifications (including ISO 8601) and after
1127       a discussion on a mailing list of calendar related topics, it appeared
1128       that there was no concise, flexible notation for handling recurring
1129       events that would handle all of the common forms I'd come up with.
1130
1131       So, as a matter of necessity, I set about inventing my own notation.
1132       As I was looking at my list, it struck me that all of the parts which
1133       specified a frequency were higher level (i.e. referred to a larger unit
1134       of time) than those parts which specified a specific value (what I've
1135       called the rtime). In other words, when the terms were laid out from
1136       year down to seconds, the frequency part was always left of specific
1137       values.
1138
1139       That led immediately to the notation described above, so I started
1140       analyzing it to figure out if it could express all of the recurring
1141       events I'd come up with. It succeeded on 100% of them. Not only that,
1142       but by playing with different values (especially different combinations
1143       of m/w/d values), I found that it would define recurring events that I
1144       hadn't even thought of, but which seemed perfectly reasonable in
1145       hindsight.
1146
1147       After a very short period, I realized just how powerful this notation
1148       was, and set about implementing it, and as I said above, of all the
1149       contributions that Date::Manip has made, I consider this to be the most
1150       important.
1151

KNOWN BUGS

1153       None known.
1154

BUGS AND QUESTIONS

1156       Please refer to the Date::Manip::Problems documentation for information
1157       on submitting bug reports or questions to the author.
1158

SEE ALSO

1160       Date::Manip        - main module documentation
1161

LICENSE

1163       This script is free software; you can redistribute it and/or modify it
1164       under the same terms as Perl itself.
1165

AUTHOR

1167       Sullivan Beck (sbeck@cpan.org)
1168
1169
1170
1171perl v5.10.1                      2011-12-07             Date::Manip::Recur(3)
Impressum