Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trap on Date created by DateString #32

Open
toxic-johann opened this issue Aug 3, 2017 · 1 comment
Open

trap on Date created by DateString #32

toxic-johann opened this issue Aug 3, 2017 · 1 comment
Labels

Comments

@toxic-johann
Copy link
Owner

toxic-johann commented Aug 3, 2017

I have bump into a terrible trap today. I think maybe I should blame why Chrome is so clever.

I need to translate a date string to a date object in my code. At first I get the date string like this: 2017-08-03 18:30:00.

'Easy job', I think. So I write like this.

const date = new Date('2017-08-03 18:30:00')

It run well in Chrome.

chrome test

But failed in safari.

safari failed

Why? Because it's an illegal date string. In IETF-compliant RFC 2822 timestamps, it stipulates that we should add T to indicate the beginning of time string.

T “T” appears literally in the string, to indicate the beginning of the time element.

So I change it to legal date string.

const date = new Date('2017-08-03 18:30:00'.replace(' ', 'T'))

But? What ?? What's wrong with the timezone.

wrong time zone

However, as we do not offer the timezone, it's correct for the browser to consider it as universal time. So, we should declare the timezone.

const date = new Date('2017-08-03 18:30:00'.replace(' ', 'T') + '+08:00')

hmmm. bugfix.

@toxic-johann toxic-johann changed the title trap on safari date trap on Date created by DateString Aug 3, 2017
@toxic-johann toxic-johann added notes and removed todo labels Aug 3, 2017
@ryancui92
Copy link

卧槽!!!!貌似不是 Safari 也有问题。

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants