Creating Period.html from Period.pm TITLE>Period
$result = inPeriod($time, $period);
The time is specified as per the
time() function, which is assumed to
be the number of non-leap seconds since January 1, 1970.
The period is specified as a string which adheres to the format
or the string ``none'' or whitespace. The string ``none'' is not case sensitive.
If the period is blank, then any time period is assumed because the time period has not been restricted. In that case, inPeriod returns 1. If the period is ``none'', then no time period applies and inPeriod returns 0.
A sub-period is of the form
Scale must be one of nine different scales (or their equivalent codes):
The same scale type may be specified multiple times. Additional scales simply extend the range defined by previous scales of the same type.
The range for a given scale must be a valid value in the form of
For the range specification v-v, if the second value is larger than the first value, the range wraps around unless the scale specification is year.
Year does not wrap because the year is never really reset, it just increments. Ignoring that fact has lead to the dreaded year 2000 nightmare. When the year rolls over from 99 to 00, it has really rolled over a century, not gone back a century. inPeriod supports the dangerous two digit year notation because it is so rampant. However, inPeriod converts the two digit notation to four digits by prepending the first two digits from the current year. In the case of 99-1972, the 99 is translated to whatever current century it is (probably 20th), and then range 99-1972 is treated as 1972-1999. If it were the 21st century, then the range would be 1972-2099.
Anyway, if v-v is 9-2 and the scale is month, September, October, November, December, January, and February are the months that the range specifies. If v-v is 2-9, then the valid months are February, March, April, May, Jun, July, August, and September. 9-2 is the same as Sep-Feb.
v isn't a point in time. In the context of the hour scale, 9 specifies the time period from 9:00:00 am to 9:59:59 am. This is what most people would call 9-10. In other words, v is discrete in its time scale. 9 changes to 10 when 9:59:59 changes to 10:00:00, but it is 9 from 9:00:00 to 9:59:59. Just before 9:00:00, v was 8.
Note that whitespace can be anywhere and case is not important. Note also that scales must be specified either in long form (year, month, week, etc.) or in code form (yr, mo, wk, etc.). Scale forms may be mixed in a period statement.
Furthermore, when using letters to specify ranges, only the first two for week days or the first three for months are significant. January is a valid specification for jan, and Sunday is a valid specification for su. Sun is also valid for su.
When specifing a range by using -, it is best to think of - as meaning through. It is 9am through 4pm, which is just before 5pm.
To specify a time period from Monday through Friday, 9am to 5pm on Monday, Wednesday, and Friday, and 9am to 3pm on Tuesday and Thursday, use a period such as
To specify a time period that extends Mon-Fri 9am-5pm, but alternates weeks in a month, use a period such as
Or how about a period that specifies winter?
This is equivalent to the previous example:
And this is too:
Wait! So is this:
To specify a period that describes every other half-hour, use something like
To specify the morning, use
Remember, 11am is not 11:00:00am, but rather 11:00:00am - 11:59:59am.
Hmmmm, 5 second blocks could be a fun period...
To specify every first half-hour on alternating week days, and the second half-hour the rest of the week, use the period