Parsing natural language timestamps

Discussion in 'Perl Misc' started by Peter Makholm, Mar 3, 2008.

  1. 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?
     
    Peter Makholm, Mar 3, 2008
    #1
    1. Advertising

  2. On Mar 3, 12:37 am, Peter Makholm <> wrote:
    > 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,
    --
    Charles DeRykus
     
    comp.llang.perl.moderated, Mar 3, 2008
    #2
    1. Advertising

  3. On Mar 3, 12:51 pm, "comp.llang.perl.moderated" <c...@blv-
    sam-01.ca.boeing.com> wrote:
    > On Mar 3, 12:37 am, Peter Makholm <> wrote:
    >
    > > 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)
    >


    That should be:

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

    --
    Charles DeRykus

    > --
    > Charles DeRykus
     
    comp.llang.perl.moderated, Mar 4, 2008
    #3
  4. "comp.llang.perl.moderated" <> writes:

    > 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
     
    Peter Makholm, Mar 5, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aidan
    Replies:
    2
    Views:
    951
    Gordon Beaton
    Aug 1, 2003
  2. JROCKS11

    natural language recognition

    JROCKS11, Dec 28, 2003, in forum: Java
    Replies:
    3
    Views:
    439
    Gordon Beaton
    Dec 29, 2003
  3. sachin
    Replies:
    2
    Views:
    340
    CBFalconer
    Feb 17, 2004
  4. Jelle Feringa // EZCT / Paris

    OCAMl a more natural extension language for python?

    Jelle Feringa // EZCT / Paris, Jan 17, 2005, in forum: Python
    Replies:
    4
    Views:
    501
  5. Andrew E
    Replies:
    4
    Views:
    390
    bytecolor
    Apr 17, 2005
Loading...

Share This Page