Parsing natural language timestamps

P

Peter Makholm

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?
 
C

comp.llang.perl.moderated

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).
...


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

If "today" is the --from:

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

* 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
23:59:59

hth,
 
C

comp.llang.perl.moderated

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

If "today" is the --from:

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

That should be:

UnixDate UnixDate(ParseDate("today"),"%b%e%Y"),"%s"
[/QUOTE]
 
P

Peter Makholm

comp.llang.perl.moderated said:
A Date::Manip concoction could help if you're say, trying to normalize
"today".

If "today" is the --from:

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

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.

//Makholm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top