Skip to content

Fix time parsing in Safari - #1

Open
miikka wants to merge 2 commits into
opqdonut:masterfrom
miikka:safari-date-time
Open

Fix time parsing in Safari#1
miikka wants to merge 2 commits into
opqdonut:masterfrom
miikka:safari-date-time

Conversation

@miikka

@miikka miikka commented Jul 28, 2018

Copy link
Copy Markdown

See the commit messages for explanation. I find this change aesthetically unpleasing, but it seems to work.

miikka added 2 commits July 28, 2018 20:10
It was not loading, because raw.githubusercontent.com serves JavaScript
with content-type 'text/plain' and furthermore with the header
'X-Content-Type-Options: nosniff', which prevents browsers from guessing
that it's JavaScript.

ISO8601-style date parsing is part of ISO8601 and according to
caniuse.com practically all current browsers support it.

https://caniuse.com/#feat=es5
There are two issues:

1. Unlike Chrome and Firefox, Safari does not parse date-time strings like
   where date and time is separated by a space as in '2018-07-28 19:30'.
   However, as promised by ECMAScript 5 spec, it does parse date-time
   strings where the separator is 'T' like '2018-07-28T19:30'.
2. ECMAScript 5 spec says that a timestring above should be parsed as an
   UTC time. ECMAScript 6 says that it should be parsed as a local time.
   *Of course* Safari does the former and the other browsers do the
   latter.

This patch attempts to deal with both issues and parse 'YYYY-MM-DD
HH:MM' as a local time in all the browsers.

I couldn't find a compability table for the second issue, which I take
to mean that nobody uses Date.parse in anger. That's probably a good
idea.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant