Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Human-readable date formats

by Loops (Curate)
on Oct 21, 2014 at 02:43 UTC ( [id://1104512]=note: print w/replies, xml ) Need Help??


in reply to Human-readable date format strings

CPAN has to have a date parser that works better for you than you can manage with regex. Date parsing is seriously thorny territory. Take a look at Date::Manip::Date or DateTime for starters. Maybe you already have and aren't happy with the lack of format control for the parsing; if so i'm not sure what to recommend.

Replies are listed 'Best First'.
Re^2: Human-readable date formats
by thewebsi (Scribe) on Oct 21, 2014 at 03:11 UTC
      Well, the DateTime module itself doesn't parse strings, but the DateTime family of modules does include DateTime::Format::ISO8601 and most of the Format modules will both parse to and pretty-print DateTime objects. The ISO8601 standard doesn't allow any old wierdness that someone might choose, but it does include most sensible formats.
      DateTime does say: "This module does not parse dates!" so that's out.

      I use DateTime to parse dates (and times) all the time. However, usually I'm parsing some specific pre-defined format, such as the format used by a particular RDBMS, the format used in email headers, or the format found in Apache log files; there are corresponding DateTime::Format::Foo modules for a wide variety of these.

      General-purpose "whatever format the user types" date parsing is a fundamentally intractable problem, because the user will type junk like "6/8", and without further context there is absolutely no way to know what they mean. The five most likely answers are probably (not necessarily in this order) June of 2008, June 8th of the current year, August 6th of the current year, June 8th in the adjacent year (coming year if it's past June 8th already, previous year otherwise), and August 6th in the adjacent year. When getting date input from users, the only really reasonable approach I've discovered so far is to ask for the year, the month, and the day, each in its own appropriately labeled field.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1104512]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-25 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found