Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
March 8, 2007, 8:19 pm
rate this thread
Let me know if this (Time::Period::Naive) is worth polishing and
uploading to CPAN. My own comment: 'Simple' or 'Easy' might be better
alternatives to 'Naive'.
Time::Period::Naive - alternate interface to Time::Period, to deal
with certain time periods (ranges) more intuitively
B<Time::Period::Naive> allows an alternate syntax for specifying
periods/ranges to B<Time::Period>.
Example: Time::Period::Naive allows you to use the following syntax:
instead of the equivalent Time::Period notation:
wd hr min , wd hr min
Keep in mind that Time::Period::Naive syntax is extremely limited
compared to that of Time::Period, but it is good for specifying
contiguous time periods that occur weekly or daily.
The day of week (followed by the at sign) is optional, but if it is
absent, it must be absent on both sides of the dash. You can use
either AM/PM notation, or 24-hour clock notation. 12:00AM is
considered the start of a day and is equivalent to 00:00 in 24-hr
clock time. Multiple ranges can be separated by commas. AM/PM
indications are not case-sensitive, and you can also use 'a' or 'p'.
B<Warning>: if you pass an empty string or an undefined value to
inPeriodNaive() as its second argument, then inPeriodNaive() indicates
success (returns 1). inPeriodNaive() behaves the same as inPeriod()
in this regard.
Likewise, the special (case-insensitive) token B<none>
causes automatic failure (0 is returned).
Whitespace is not significant in the time period specification
string; all space is stripped from the second argument before parsing.
=head2 IMPORTANT DIFFERENCES FROM Time::Period
The range is considered to extend up to but not include the second
time specification, e.g. "12:00-12:01" would be equivalent to the
Time::Period syntax "hr min ", and I<not> "hr min ".
=head2 WHEN NOT TO USE Time::Period::Naive
Use B<Time::Period> instead of B<Time::Period::Naive> whenever you are
B<not> dealing with one or a small number of contiguous time intervals
that happen weekly or daily.
For instance, the example "Monday through Friday, 9am to 5pm" from the
Time::Period man page gets a little awkward:
Mon@9:00am-Mon@5:00pm, Tue@9:00am-Tue@5:00pm, Wed@9:00am-Wed@5:00pm,
compared to the elegant Time::Period syntax: