Skip to content

more docs for ParseTime's time zone handling ? #172

@simonmichael

Description

@simonmichael

I got very confused while trying to parse the local date from a date-time stamp (ie the corresponding date in my local time zone). It's easy to assume that ParseTime's LocalTime instance would be affected by a time zone in the timestamp. In fact it seems to just discard it, treating the timestamp as a local time:

ghci> parseTimeM True defaultTimeLocale "%Y-%m-%dT%H:%M:%S%Z" "2021-01-03T01:00:00-0000" :: Maybe LocalTime
Just 2021-01-03 01:00:00
ghci> parseTimeM True defaultTimeLocale "%Y-%m-%dT%H:%M:%S%Z" "2021-01-03T01:00:00-0200" :: Maybe LocalTime
Just 2021-01-03 01:00:00
ghci> parseTimeM True defaultTimeLocale "%Y-%m-%dT%H:%M:%S%Z" "2021-01-03T01:00:00+0200" :: Maybe LocalTime
Just 2021-01-03 01:00:00

Is this the best that can be done ? I think it would be good to mention it in the haddocks.

Related: To achieve my goal, I planned to parse to UTCTime, which of course does take the time zone into account; then convert to my local time zone with utcToLocalTime. But from #haskell I learned: "note that if you convert UTC to LocalTime using getCurrentTimeZone as an argument, you may get wrong result (if, for example, you are currently on summer time, but weren't at the date in the string)". Is there any way around this using the time package ? It was suggested that utcToLocalTimeTZ in the tz package would handle this right, perhaps for past dates only ? <- a mistake, hopefully.

Thank you for time !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions