time package - parsing of incorrect data
ashley at semantic.org
Mon May 25 19:02:04 EDT 2009
Paolo Losi wrote:
> Hi all,
> I'm experimenting with time package parsing functionalities.
> I'm trying to verify what happens with inconsistent input data.
> From what I've seen, incorrect days are "truncated" while incorrect
> hours are left unmodified leading to inconsistent data.
> Is this the intended behaviour? Would it be more appropriate
> to return a parsing Error (Nothing in the following example)?
> with time-1.1.3:
> > parseTime defaultTimeLocale "%Y-%m-%d %H:%M" "2008-04-31 25:30" ::
> Maybe LocalTime
> Just 2008-04-30 25:30:00
> parseTime defaultTimeLocale "%H:%M:%S" "25:74:99" :: Maybe TimeOfDay
Currently the parsing code uses construction functions like this:
fromGregorian :: Integer -> Int -> Int -> Day
TimeOfDay :: Int -> Int -> Pico -> TimeOfDay -- just a constructor
Possibly it should use instead "validating constructors" that return a
Maybe type. But note that some minutes have 61 seconds, and given that
TimeOfDay might be local civil time (UTC + time zone offset), it can be
any minute. So these must be allowed:
Just as UTC requires occasional minutes that have more than 60 seconds,
there's a question of whether TimeOfDay might be used with timescales
where minutes can have more than 61 seconds. I believe it would be of
the order of millions of years before an extended UTC would need more
than one leap second every minute.
So a validating "fromHourMinuteSecondValid" should check fields like this:
0 <= hour < 24
0 <= minute < 60
0 <= second < 61
More information about the Libraries