-
-
Notifications
You must be signed in to change notification settings - Fork 136
new Date() does not work as expected after time zone change #961
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
Comments
From @EddyVerbruggen on February 26, 2018 19:6 Googling this a little, I wouldn't be surprised if this is a bug in V8 rather than NativeScript. |
From @NathanaelA on February 26, 2018 21:32 An easy way to see would be to run the latest version of Chrome, and do the same JS test. This would tell you if it is a bug in V8 vs a NativeScript issue. Now to get you going; rather than use |
@moserc I am suspecting that the V8 caches the device locale upon initialization, and is not notified of time zone changes. Perhaps there is no such mechanism in V8. Node.js and Chrome would likely inhibit similar behavior. |
@NickIliev your workaround is good for now but we are actually trying to use the momentjs library which seems to be broken in the same way...... @Pip3r4o We used Angular JS to test Date() with Chrome and it seems to work as expected both on my PC and Android device. html: <button (click)="refreshDate()" type="submit" >Refresh Date</button>
<label >{{date}}</label> codebehind: refreshDate() {
this.date = Date();
} Does this show V8 is working correctly? "You can tell when someone's been a programmer for a while because they develop a deep-seated fear of time zone problems." --Randall Munroe, xkcd 1883 |
@moserc In Android you can have an intent filter for a time-zone change, however, you'd have to register a broadcast receiver whose implementation will invoke the v8 notification. I suppose what we could help with from our end is to expose the V8 time zone change notification statically to Java, which NativeScript developers will be able to call at their own discretion. Right now we can't commit to any ETA on when that will be available. |
@Pip3r4o In an effort to clarify, our app does not necessarily need to be notified of a timezone or DST change. However, we would like the correct timestamp to be available whenever we call Date(). It seems to me that Date() should work the same if called from a webpage on Chrome or if called from a Nativescript app, and it does not. It seems to work perfectly on a webpage. Maybe this does not change anything since I do not know the underlying implementation of the Date() function on Nativescript but I wanted to make sure you understand the problem we are experiencing. |
There are no underlying Nativescript specifics as far as the Date object is concerned - it comes straight from the V8 engine. I don’t see a straightforward way for us to implement the automatic time zone change notifier. In the case of the Chrome browser - it’s coded in the Chrome implementation. Chrome being an app that embeds the V8 engine. Similarly, a NativeScript application will have to notify of the time zone change. The way to go is using a broadcast listener in Android, hence my proposal to expose the V8 notification API to Java. |
From @moserc on February 26, 2018 17:25
Issue
Date() does not return correct Timezone Offset unless the app is restarted in the new Timezone.
Creating the Issue
When I am running a Nativescript app in my local timezone, Date() correctly returns:
If I change to CST timezone without restarting the app, Date() returns the correct Timezone but incorrect Timezone Offset:
If I shut down the app and restart it (without changing from CST timezone), Date() correctly returns:
Can you please help us?
More info
Platform: Android
CLI: 3.2.1
-C
Copied from original issue: NativeScript/NativeScript#5469
The text was updated successfully, but these errors were encountered: