# translate human-readable time shorthand - Page 2

•  Subject
• Author
• Posted on

## Re: translate human-readable time shorthand

There is some ambiguity in the concept of /duration/ when applied to
such large units as years and months. A "unit" of duration should have
a fixed definition that doesn't depend upon the date and time when the
period starts and stops.

For example, if you say you want your egg boiled for "three minutes",
you mean exactly 180 seconds, regardless of when you actually place the
egg into the boiling water and whether or not a leap second is added to
the calendar during the cooking. If you want your concrete driveway to
cure for "three days" before parking your car on it, you want to wait
no less than 259,200 seconds, even if you happen to pour the concrete
on the Friday before daylight savings goes into effect.

So we should try to agree that one minute of duration is 60 seconds,
one hour is 60 minutes, one day is 24 hours, and one week is 7 days,
regardless of when those periods start or stop.

When it comes to months and years, there is more ambiguity and more
possibility for disagreement. A solar year is 365.242 days, or
31,556,908.8 seconds. An average "month" would be one-twelfth of that,
or 2,629,742.4 seconds = 30.4368 days. The potential disagreements of
what constitutes a "year" or a "month" probably preclude those terms
from being used as units of duration unless it is obvious what values
are being used.

--
Jim Gibson

## Re: translate human-readable time shorthand

Depending on the context I think that '1 day' could mean both a 24 hours
duration or the next day at the same (local) time. When the duration
is the primary object I would understand 24 hours and when the point in
time is the primary object I would understand at the same time the next
day.

In some cases I use the same interpretation when I change time zone due
to travel (at least for time zone changes within a few hours). So if I
have a recurring task I have to perform every 2 days I would default to
do it on the same time of the day accoridng to the local time.

For month and year I think I would make the same distinctions, where the
duration would be some sort of normalized duration (30 days/365 days)
and the point in time would depend on the specific month or year.

A recurring monthly meeting would by default be at the same day of the
month. For a duration of several months I would probably just consider
the difference negligible.

//Makholm

## Re: translate human-readable time shorthand

I am not at all familiar with the fancy-pants newfangled stuff in
regexps like in that second example.  To save other people trouble,
- "m" has to be expressed as "mn" (in Date::Manip::Delta,
"m" appears to be "month" and "mn" is "minute")
- Date::Manip::Delta requires space (or comma) before digits.
Find each place where the character before is not a digit and the
character following is a digit, and put a space there.
(Those are zero-width assertions.)  I see no reason why it could not
be expressed, albeit probably with less efficiency, as
s/(\d+)/ \$1/g

--
Tim McDaniel, tmcd@panix.com

## Re: translate human-readable time shorthand

Quoth tmcd@panix.com:

'Newfangled'?! (?<!) was added in 5.005, released in 1998. (?=) was
already there at that point, but the perldeltas don't go back further
than 5.004 so I don't know when it appeared.

Nor do I. I was thinking 'I want to add a space between every non-digit
followed by a digit', so that's what I wrote. I was actually thinking in
terms of '\b for digits', which is why I was using zero-width
assertions.

Ben

## Re: translate human-readable time shorthand

FANCY-PANTS newfangled.  'Tweren't in Perl 4.038.
*ptooo*  [ping!]

Seriously, I've never had cause to use a zero-width assertion, or
possibly any other "?" syntax other than the one that keeps (...) from
touching \$digit ("(?: ... )"), and that I had to look up just now.

--
Tim McDaniel, tmcd@panix.com

## Re: translate human-readable time shorthand

all these are very wise and clever except ... that the OP is missing !

## Re: translate human-readable time shorthand

The OP moved his question over to comp.lang.perl.modules -- still
looking for a module that would do the conversion for him. He also made
it clear that the context of the question is in the time delays used by
'at', the Unix task scheduling utility, so anything longer than a week
is probably irrelevant, and the interpretation of months and years is
moot.

--
Jim Gibson

## Re: translate human-readable time shorthand

I have the impression that cron (as an analogy) has had extensive work
to make corner cases work, like 1-3 AM on daylight-saving change day,
or other clock adjustments.  I mention that only as an example about
how time handling can be tricky and so I would be more inclined to use
a module that shows some signs of handling intervals properly.

--
Tim McDaniel, tmcd@panix.com

## Re: translate human-readable time shorthand

tmcd@panix.com (Tim McDaniel) writes:

The problem is underspecified and can't be solved 'calendarically
correct' based on the available information. More accurately, the
problem consists of two subproblems, namely 1) parse the string in order to
find the number/unit combinations in it. This is trivial and can be
done with a single line of code. And then 2) 'interpret this
information in a suitable way'. Because 2) can't be solved without
information the OP isn't willing to provide, all example code which
was posted necessarily solved problem 1).

## Re: translate human-readable time shorthand

Quite true, quite true.  If they really do want _duration_, then now +
duration in UTC -> convert to a timezone at need is the way.

--
Tim McDaniel, tmcd@panix.com

## Re: translate human-readable time shorthand

tmcd@panix.com (Tim McDaniel) writes:

[...]

Since this is such a nice illustration of the 'garbage in - garbage
out' issue: What precisely do you mean by 'work'? Surely not 'should
run for three hours every day except that it should run for fewer
than three hours on some random day in spring and for fewer than three
hours on some random day in fall if the system default time zone
currently happens to have some "I'm an early riser and it really
pisses me off that others are still asleep !!!!"[*] voodoo convention?

[*] IIRC, Wikipedia states that "Random Clockjump Day" was invented
before 1914 by some British guy who 'felt lonely' on his seriously
early morning ridw ...

## Re: translate human-readable time shorthand

tmcd@panix.com (Tim McDaniel) writes:

[...]

Since this is such a nice illustration of the 'garbage in - garbage
out' issue: What precisely do you mean by 'work'? Surely not 'should
run for three hours every day except that it should run for fewer
than three hours on some random day in spring and for more than three
hours on some random day in fall if the system default time zone
currently happens to have some "I'm an early riser and it really
pisses me off that others are still asleep !!!!"[*] voodoo convention?

[*] IIRC, Wikipedia states that "Random Clockjump Day" was invented
before 1914 by some British guy who 'felt lonely' on his seriously
early morning ride ...

## Re: translate human-readable time shorthand

at 03:48 PM, tmcd@panix.com (Tim McDaniel) said:

s/\s*(\d+)/ \$1/g

--
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not

## Re: translate human-readable time shorthand

Then there are two spaces, which the module accepts, and since the
string is only to be used for parsing, it doesn't have to look pretty.

Yeah, you could strip leading whitespace.  But the module actually
implements [,\s]+ to delimit fields, as I recall, so if you want
something minimal, you'd have to strip that.

--
Tim McDaniel, tmcd@panix.com