rluiten / elm-date-extra

Elm Date Extra library add/subtract/diff/format etc dates
http://package.elm-lang.org/packages/rluiten/elm-date-extra/latest
BSD 3-Clause "New" or "Revised" License
75 stars 36 forks source link

Date.Extra.Format.isoString isn't parsable in Safari. #29

Closed mrozbarry closed 7 years ago

mrozbarry commented 7 years ago

I'm building an elm app that builds a Date.Date from two different sources, and gets the local timezone to submit to a server in an iso8601 format. To extract the local timezone, I was originally doing:

localTimeZone : String
localTimeZone =
  (Date.fromTime 0)
    |> Date.Extra.Format.isoString
    |> String.right 5
    -- Result : -0500

Later, I combine my date and time parts with this local timezone and do a Date.fromString which I'm guessing backs onto javascript's Date implementation. This works perfectly fine in Chrome and Firefox, but Safari throws an error saying the date I assembled isn't a proper 8601 format.

After some fiddling, I discovered Safari would only accept a timezone if it was formatted with a : between the hour and minute, ie 1999-01-01T12:00:00-05:00.

Would it be possible to have isoString output with that format, as it can be parsed on all browsers using Date.fromString from elm's core packages.

rluiten commented 7 years ago

Sounds eminently reasonable. Had a look at the code the format specifier :z does put a colon out for zone.

Hmm but the default isn't using it for some reason. isoMsecOffsetFormat = "%Y-%m-%dT%H:%M:%S.%L%z"

I'll look into this next time I am in code base.

mrozbarry commented 7 years ago

That would be perfect - if I have some time and beat you to it, I'll do a PR as well.

mrozbarry commented 7 years ago

@rluiten I just did a fresh install of my project, and it looks like the ":" is back in the timezone - was this fixed?

rluiten commented 7 years ago

I have not updated the lib yet.

mrozbarry commented 7 years ago

Oh, I see, I had a bug in my code, which was also affected by this missing ":".

rluiten commented 7 years ago

I am about to publish this change to include : in Format.isoString result and in exported format string Format.isoMsecOffsetFormat in v8.2.0.