Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

DateTime parsing and midnight

by pokki (Scribe)
on Nov 11, 2010 at 13:50 UTC ( #870856=perlquestion: print w/ replies, xml ) Need Help??
pokki has asked for the wisdom of the Perl Monks concerning the following question:

I'm planning on using DateTime::Format::Flexible or DateTime::Format::Natural to parse datetime strings. The problem is that the string to be parsed may or may not contain a time component, e.g. "2010-11-11 Thu" is valid, as is "2010-11-11 Thu 22:00".

How do I differentiate between a DateTime object that was built from a string without a time component, and one which was built from, say, "2010-11-11 Thu 0:00", since both would have the same time component?

(This is a calendaring type application, so "no time component" is to be interpreted as "all day", not just as "user forgot to set date so we'll treat it as an error" or "use a default". It's also built from an existing format which I can't extend to manually indicate "all day" type timestamps.)

Update I may not have made myself clear, but the time in the string is not a duration, it's part of a timestamp, e.g. "Meeting <2010-11-11 Thu 13:00>" means that a meeting is scheduled for November 11 at 13:00 (or 1 PM).

Comment on DateTime parsing and midnight
Re: DateTime parsing and midnight
by Corion (Pope) on Nov 11, 2010 at 13:56 UTC

    I wouldn't lump the two together. One is a point in time, easiest modelled as DateTime instance. The other is a duration with a (fixed) start and endpoint or with a fixed start point and a length given in (say) minutes.

    As the two are different, use different parsers.

      I may not have made myself clear, but the time in the string is not a duration, it's part of a timestamp, e.g. "Meeting <2010-11-11 Thu 13:00>" means that a meeting is scheduled for November 11 at 13:00 (or 1 PM).

        Yes. That is a point in time. But the other string is a duration, as it is meant for the whole day, isn't it?

        In any way, as you seem to want the two to be treated differently, you will have to do so.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://870856]
Approved by rovf
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-11-25 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls