Parsing natural language timestamps

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a command line application where the use specifies a time span
with two arguments --from and --to. At the moment I'm using strptime
from Date::Parse, but it would be nice to support dates like '2 days
ago', 'today', 'next friday'.

If the user doesn't specifies a exact time but just a day I would like
to have the from argument use the start of the date (00:00:00) and the
to argument use the end of the date (23:59:59).

Date::Manip and Time::ParseDate both parses these natural language
timestamps, but I can't get either to work quite as I need. Both seem
to have 'today' parsed as 'right now' as default.

Date::Manip have a TodayIsMidnight setting, but 'tomorrow' is still '24
hours from right now' and I can't differ between wether the user used
the not specific 'today' or '2008-03-03 00:00:00' which would mean
differing things in the to argument.

Time::ParseDate has a nice TIME_REQUIRED setting, but it seems to be
non-working for relative dates like today and tomorrow by coding.

Any idears for a solution?


Re: Parsing natural language timestamps

Quoted text here. Click to load it

A Date::Manip concoction could help if you're say, trying to normalize

If "today" is the --from:


* This gives the epoch for today=20080303 00:00:00

If "today" is the --to, use the above replacing "today" with
"tomorrow", then subtract 1 for an end-of-day epoch, ie, 20080303

Charles DeRykus

Re: Parsing natural language timestamps

On Mar 3, 12:51 pm, "comp.llang.perl.moderated" <c...@blv-> wrote:
Quoted text here. Click to load it

That should be:

UnixDate UnixDate(ParseDate("today"),"%b%e%Y"),"%s"

Charles DeRykus

Quoted text here. Click to load it

Re: Parsing natural language timestamps

Quoted text here. Click to load it

But I'm not trying to normalize 'today', that is easy even without
using Date::Manip. I'm trying to handle anything the user would like
to write as a time.

More precisely I would like to have the start and end of whatever
fuzzy natural language timestamp the user would use. So I have to
figure out which precision the given timestamp has (a day, an hour, a
minute) and the return the a interval of 86400, 3600, or 60 seconds.


Site Timeline