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

new Date().get('timezone'); Always returns GMT #1355

Open
jbgithub opened this issue Nov 23, 2017 · 0 comments
Open

new Date().get('timezone'); Always returns GMT #1355

jbgithub opened this issue Nov 23, 2017 · 0 comments

Comments

@jbgithub
Copy link

The value/format returned by Date.toString() has changed. I checked this in Chrome, Firefox, Internet Explore and Edge.

I'm located in the America/Los_Angeles timezone, here is an example of what is returned:

Wed Nov 22 2017 16:47:56 GMT-0800 (Pacific Standard Time)

The regular expression use in getTimezone() always returns GMT:
this.toString() .replace(/^.? ([A-Z]{3}).[0-9]{4}.$/, '$1')
.replace(/^.*?(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+)$/, '$1$2$3');

I modified the first RE to remedy the issue:
this.toString() .replace(/^.* (([A-Za-z ]+)|[A-Z]{3}).$/, '$1')
.replace(/^.
?(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+)$/, '$1$2$3');

With this modification, PST is now returned. This works for the 4 US time zones. You will probably need additional changes for other time zones.

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

No branches or pull requests

1 participant