1Period(3) User Contributed Perl Documentation Period(3)
2
3
4
6 Time::Period - A Perl module to deal with time periods.
7
9 "use Time::Period;"
10
11 "$result = inPeriod($time, $period);"
12
14 The inPeriod function determines if a given time falls within a given
15 period. inPeriod returns 1 if the time does fall within the given
16 period, 0 if not, and -1 if inPeriod detects a malformed time or
17 period.
18
19 The time is specified as per the "time()" function, which is assumed to
20 be the number of non-leap seconds since January 1, 1970.
21
22 The period is specified as a string which adheres to the format
23
24 sub-period[, sub-period...]
25
26 or the string "none" or whitespace. The string "none" is not case sen‐
27 sitive.
28
29 If the period is blank, then any time period is assumed because the
30 time period has not been restricted. In that case, inPeriod returns 1.
31 If the period is "none", then no time period applies and inPeriod
32 returns 0.
33
34 A sub-period is of the form
35
36 scale {range [range ...]} [scale {range [range ...]}]
37
38 Scale must be one of nine different scales (or their equivalent codes):
39
40 Scale ⎪ Scale ⎪ Valid Range Values
41 ⎪ Code ⎪
42 *******⎪*******⎪************************************************
43 year ⎪ yr ⎪ n where n is an integer 0<=n<=99 or n>=1970
44 month ⎪ mo ⎪ 1-12 or jan, feb, mar, apr, may, jun, jul,
45 ⎪ ⎪ aug, sep, oct, nov, dec
46 week ⎪ wk ⎪ 1-6
47 yday ⎪ yd ⎪ 1-365
48 mday ⎪ md ⎪ 1-31
49 wday ⎪ wd ⎪ 1-7 or su, mo, tu, we, th, fr, sa
50 hour ⎪ hr ⎪ 0-23 or 12am 1am-11am 12noon 12pm 1pm-11pm
51 minute ⎪ min ⎪ 0-59
52 second ⎪ sec ⎪ 0-59
53
54 The same scale type may be specified multiple times. Additional scales
55 simply extend the range defined by previous scales of the same type.
56
57 The range for a given scale must be a valid value in the form of
58
59 v
60
61 or
62
63 v-v
64
65 For the range specification v-v, if the second value is larger than the
66 first value, the range wraps around unless the scale specification is
67 year.
68
69 Year does not wrap because the year is never really reset, it just
70 increments. Ignoring that fact has lead to the dreaded year 2000
71 nightmare. When the year rolls over from 99 to 00, it has really
72 rolled over a century, not gone back a century. inPeriod supports the
73 dangerous two digit year notation because it is so rampant. However,
74 inPeriod converts the two digit notation to four digits by prepending
75 the first two digits from the current year. In the case of 99-1972,
76 the 99 is translated to whatever current century it is (probably 20th),
77 and then range 99-1972 is treated as 1972-1999. If it were the 21st
78 century, then the range would be 1972-2099.
79
80 Anyway, if v-v is 9-2 and the scale is month, September, October, No‐
81 vember, December, January, and February are the months that the range
82 specifies. If v-v is 2-9, then the valid months are February, March,
83 April, May, Jun, July, August, and September. 9-2 is the same as
84 Sep-Feb.
85
86 v isn't a point in time. In the context of the hour scale, 9 specifies
87 the time period from 9:00:00 am to 9:59:59 am. This is what most peo‐
88 ple would call 9-10. In other words, v is discrete in its time scale.
89 9 changes to 10 when 9:59:59 changes to 10:00:00, but it is 9 from
90 9:00:00 to 9:59:59. Just before 9:00:00, v was 8.
91
92 Note that whitespace can be anywhere and case is not important. Note
93 also that scales must be specified either in long form (year, month,
94 week, etc.) or in code form (yr, mo, wk, etc.). Scale forms may be
95 mixed in a period statement.
96
97 Furthermore, when using letters to specify ranges, only the first two
98 for week days or the first three for months are significant. January
99 is a valid specification for jan, and Sunday is a valid specification
100 for su. Sun is also valid for su.
101
102 PERIOD EXAMPLES
103
104 To specify a time period from Monday through Friday, 9am to 5pm, use a
105 period such as
106
107 wd {Mon-Fri} hr {9am-4pm}
108
109 When specifing a range by using -, it is best to think of - as meaning
110 through. It is 9am through 4pm, which is just before 5pm.
111
112 To specify a time period from Monday through Friday, 9am to 5pm on Mon‐
113 day, Wednesday, and Friday, and 9am to 3pm on Tuesday and Thursday, use
114 a period such as
115
116 wd {Mon Wed Fri} hr {9am-4pm}, wd{Tue Thu} hr {9am-2pm}
117
118 To specify a time period that extends Mon-Fri 9am-5pm, but alternates
119 weeks in a month, use a period such as
120
121 wk {1 3 5} wd {Mon Wed Fri} hr {9am-4pm}
122
123 Or how about a period that specifies winter?
124
125 mo {Nov-Feb}
126
127 This is equivalent to the previous example:
128
129 mo {Jan-Feb Nov-Dec}
130
131 As is
132
133 mo {jan feb nov dec}
134
135 And this is too:
136
137 mo {Jan Feb}, mo {Nov Dec}
138
139 Wait! So is this:
140
141 mo {Jan Feb} mo {Nov Dec}
142
143 To specify a period that describes every other half-hour, use something
144 like
145
146 minute { 0-29 }
147
148 To specify the morning, use
149
150 hour { 12am-11am }
151
152 Remember, 11am is not 11:00:00am, but rather 11:00:00am - 11:59:59am.
153
154 Hmmmm, 5 second blocks could be a fun period...
155
156 sec {0-4 10-14 20-24 30-34 40-44 50-54}
157
158 To specify every first half-hour on alternating week days, and the sec‐
159 ond half-hour the rest of the week, use the period
160
161 wd {1 3 5 7} min {0-29}, wd {2 4 6} min {30-59}
162
164 1.20
165
167 Version 1.20
168 ------------
169 - Added the ability to specify no time period.
170
171 Version 1.13
172 ------------
173 - Cleaned up the error checking code.
174
175 Version 1.12
176 ------------
177 - Updated email and web space information.
178
179 Version 1.11
180 ------------
181 - Minor bug fix in 1.10.
182
183 Version 1.10
184 ------------
185 - Released.
186
188 Patrick Ryan <pgryan@geocities.com>
189
191 Copyright (c) 1997 Patrick Ryan. All rights reserved. This Perl mod‐
192 ule uses the conditions given by Perl. This module may only be dis‐
193 tributed and or modified under the conditions given by Perl.
194
196 August 26, 1997
197
199 This distribution can be found at
200
201 http://www.geocities.com/SiliconValley/Lakes/8456/
202
203 or
204
205 http://www.perl.com/CPAN/modules/by-module/Time/
206
207
208
209perl v5.8.8 1997-08-26 Period(3)