After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 678507 - date doesn't update after changing timezone
date doesn't update after changing timezone
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: calendar
unspecified
Other Linux
: Normal normal
: 3.16
Assigned To: gnome-shell-maint
gnome-shell-maint
: 734236 744631 765897 (view as bug list)
Depends on: 739790
Blocks:
 
 
Reported: 2012-06-20 22:49 UTC by William Jon McCann
Modified: 2017-10-25 16:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
screenshot (42.40 KB, image/png)
2012-06-20 22:49 UTC, William Jon McCann
  Details
Screenshot showing other bugs apart from date update (187.91 KB, image/png)
2013-11-01 14:25 UTC, Parin Porecha
  Details
Screenshot showing wrong date detection (76.81 KB, image/png)
2013-11-01 14:27 UTC, Parin Porecha
  Details
Proposed patch to fix the bug reported and the ones mentioned in comments (7.47 KB, patch)
2013-11-04 15:18 UTC, Parin Porecha
needs-work Details | Review
Patch to gjs to add a wrapper for JS_ClearDateCaches (1.21 KB, patch)
2014-05-04 15:25 UTC, Martin Andersson
reviewed Details | Review
Rebuild the calendar after a time zone change (1.98 KB, patch)
2014-05-04 15:25 UTC, Martin Andersson
none Details | Review
Add wrapper for JS_ClearDateCaches (1.28 KB, patch)
2014-05-04 16:09 UTC, Martin Andersson
none Details | Review
Rebuild the calendar after a time zone change (2.22 KB, patch)
2014-05-04 16:10 UTC, Martin Andersson
none Details | Review
Add wrapper for JS_ClearDateCaches (1.59 KB, patch)
2014-05-04 18:05 UTC, Martin Andersson
none Details | Review
Rebuild the calendar after a time zone change (2.44 KB, patch)
2014-05-04 18:06 UTC, Martin Andersson
none Details | Review
Rebuild the calendar after a time zone change (2.46 KB, patch)
2015-04-22 21:25 UTC, Martin Andersson
none Details | Review
Rebuild the calendar after a time zone change (2.46 KB, patch)
2015-08-14 00:18 UTC, Martin Andersson
committed Details | Review

Description William Jon McCann 2012-06-20 22:49:39 UTC
Created attachment 216882 [details]
screenshot

I changed timezone earlier today from HK to BOS. The shell clock updated correctly but the calendar still thinks it is tomorrow.
Comment 1 William Jon McCann 2012-12-19 00:35:22 UTC
Still happening.
Comment 2 poornima 2013-04-23 15:03:17 UTC
is the bug solved? If not can i have the link to the code?
Comment 3 Parin Porecha 2013-11-01 14:25:04 UTC
Created attachment 258734 [details]
Screenshot showing other bugs apart from date update

On changing the timezone, not only the date does not get updated in the calendar, but tasks are also 
displayed as scheduled for wrong days.

I created tasks in timezone AKDT and changed to HST (Just an example. The bug also occurs with more timezones).
Comment 4 Parin Porecha 2013-11-01 14:27:49 UTC
Created attachment 258736 [details]
Screenshot showing wrong date detection

Dates are also detected wrongly on timezone change. In the screenshot, I've selected 8th November, but the one detected to display tasks is 7th Nov.
Comment 5 Parin Porecha 2013-11-04 15:18:07 UTC
Created attachment 258936 [details] [review]
Proposed patch to fix the bug reported and the ones mentioned in comments

I've attached a patch for this bug as well as for the bugs in events list. The bug was due to JavaScript returning false dates on correct timezones.
Comment 6 Carlos Soriano 2014-03-12 15:32:04 UTC
Review of attachment 258936 [details] [review]:

I'm not sure about the overall patch. So is javascript which is giving bad dates? where? in new Date()? or in toLocaleFormat()?
or do you just need to call date.toLocaleFormat each time? (which is fine)

::: js/ui/calendar.js
@@ +87,3 @@
+    else
+        date = new Date();
+    let locale_formatted_date = date.toLocaleFormat("%Y-%m-%dT%H:%M:%S");

use ratio character instead of semicolons

@@ +154,3 @@
+    return abbreviations[dayNumber];
+}
+        C_("list tuesday", "Tuesday"),

is this necesary? why not using toLocaleFormat?

@@ +212,3 @@
+    return abbreviations[monthNumber];
+}
+        /* Translators: Calendar month for June */

is this necesary? why not using toLocaleFormat?

@@ +838,3 @@
         if (_sameYear(day, now))
             /* Translators: Shown on calendar heading when selected day occurs on current year */
+            dayString = _getEventDay(day.getDay()) + ', ' + _getCalendarMonth(day.getMonth()) + ' ' + day.getDate();

Translatable strings have to be single strings, not compose strings.
Also, this is not even translatable. You need _(foo)

@@ +841,3 @@
         else
             /* Translators: Shown on calendar heading when selected day occurs on different year */
+            dayString = _getEventDay(day.getDay()) + ', ' + _getCalendarMonth(day.getMonth()) + ' ' + day.getDate() + ', ' + day.getFullYear();

ditto

::: js/ui/dateMenu.js
@@ +127,3 @@
                  * isn't very big.
                  */
+                let updated_now = now.toLocaleFormat("%Y-%m-%dT%H:%M:%S");

need to be translatable and a comment to translators of what it means.
Also, what happens with those people who use AM/PM? it's impossible to set with this
Comment 7 Bastien Nocera 2014-03-13 08:45:33 UTC
(In reply to comment #6)
> Review of attachment 258936 [details] [review]:
> 
> I'm not sure about the overall patch. So is javascript which is giving bad
> dates? where? in new Date()? or in toLocaleFormat()?
> or do you just need to call date.toLocaleFormat each time? (which is fine)
> 
> ::: js/ui/calendar.js
> @@ +87,3 @@
> +    else
> +        date = new Date();
> +    let locale_formatted_date = date.toLocaleFormat("%Y-%m-%dT%H:%M:%S");
> 
> use ratio character instead of semicolons

No. This breaks LTR languages.
Comment 8 Martin Andersson 2014-04-21 18:51:53 UTC
This bug happens because SpiderMonkey caches the timezone information, so when the timezone is changed calls like getDate and getHours still use the old timezone.

A function (JS_ClearDateCaches) was added (see bug https://bugzilla.mozilla.org/show_bug.cgi?id=285615) to SpiderMonkey that can be used to invalidate the cache. So the solution to this issue is to call that function when the timezone is changed.

I tried to create a patch for this issue, but I'm new to javascript programming and the gnome stack and I couldn't figure out how to properly solve it. I did an ugle hack just so to see if this was indeed the root cause by adding a call to JS_ClearDateCaches to the, global, log function in gjs/context.cpp and a small change to calendar.js in gnome-shell. That did indeed fix the issue.

Then I tried to make a proper fix by adding a new function to gjs/context.cpp (I also added it to the global_funcs array) that would call JS_ClearDateCaches, but I couldn't get that to work, when I tried to call that function from calendar.js it just said that there was no such function.

That's how far I got and I would like some pointers on how I can proceed.
Comment 9 Martin Andersson 2014-05-04 15:25:05 UTC
Created attachment 275812 [details] [review]
Patch to gjs to add a wrapper for JS_ClearDateCaches
Comment 10 Martin Andersson 2014-05-04 15:25:47 UTC
Created attachment 275813 [details] [review]
Rebuild the calendar after a time zone change
Comment 11 Jasper St. Pierre (not reading bugmail) 2014-05-04 15:26:35 UTC
Review of attachment 275812 [details] [review]:

I'd prefer if this went into modules/system.cpp instead.
Comment 12 Martin Andersson 2014-05-04 15:33:52 UTC
During my work with this bug I found that JS_ClearDateCaches behaved strangly, it didn't update the time when changing from certain time zones. I think I found that issue and filed bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1004706
Comment 13 Martin Andersson 2014-05-04 16:09:49 UTC
Created attachment 275819 [details] [review]
Add wrapper for JS_ClearDateCaches
Comment 14 Martin Andersson 2014-05-04 16:10:42 UTC
Created attachment 275820 [details] [review]
Rebuild the calendar after a time zone change
Comment 15 Jasper St. Pierre (not reading bugmail) 2014-05-04 16:17:59 UTC
Review of attachment 275819 [details] [review]:

Would it be possible to add a call to tzset here to work around the SpiderMonkey bug?
Comment 16 Martin Andersson 2014-05-04 17:12:08 UTC
(In reply to comment #15)
> Review of attachment 275819 [details] [review]:
> 
> Would it be possible to add a call to tzset here to work around the
> SpiderMonkey bug?

Yes, I tried it and it worked. Should I add it?
Comment 17 Jasper St. Pierre (not reading bugmail) 2014-05-04 17:34:27 UTC
Yes. At the same time, could also add a comment in the gnome-shell patch explaining why we have to clear the datetime cache with a link to this bug, and also add a comment around the tzset call that points to the upstream SpiderMonkey bug as well?
Comment 18 Martin Andersson 2014-05-04 17:36:07 UTC
(In reply to comment #17)
> Yes. At the same time, could also add a comment in the gnome-shell patch
> explaining why we have to clear the datetime cache with a link to this bug, and
> also add a comment around the tzset call that points to the upstream
> SpiderMonkey bug as well?

ok, will do
Comment 19 Martin Andersson 2014-05-04 18:05:50 UTC
Created attachment 275836 [details] [review]
Add wrapper for JS_ClearDateCaches
Comment 20 Martin Andersson 2014-05-04 18:06:34 UTC
Created attachment 275837 [details] [review]
Rebuild the calendar after a time zone change
Comment 21 Florian Müllner 2014-08-06 18:33:22 UTC
*** Bug 734236 has been marked as a duplicate of this bug. ***
Comment 22 Bastien Nocera 2014-11-07 15:26:05 UTC
Comment on attachment 275836 [details] [review]
Add wrapper for JS_ClearDateCaches

Moved gjs patch to bug 739790
Comment 23 Florian Müllner 2015-02-16 23:31:49 UTC
*** Bug 744631 has been marked as a duplicate of this bug. ***
Comment 24 Martin Andersson 2015-04-22 21:25:52 UTC
Created attachment 302186 [details] [review]
Rebuild the calendar after a time zone change

Updated patch for 3.16
Comment 25 Oliver Propst 2015-06-21 11:57:25 UTC
Should this bug not be marked as "fixed"?
Comment 26 Bastien Nocera 2015-06-21 12:29:49 UTC
(In reply to Oliver Propst from comment #25)
> Should this bug not be marked as "fixed"?

No, we still need the gnome-shell part of the patch.
Comment 27 Florian Müllner 2015-08-12 19:07:53 UTC
Review of attachment 302186 [details] [review]:

::: js/ui/calendar.js
@@ +552,3 @@
 
+    updateTimeZone: function() {
+        // The calendar need to be rebuilt after a time zone update beacuse

*because

@@ +554,3 @@
+        // The calendar need to be rebuilt after a time zone update beacuse
+        // the date might have changed.
+        this._rebuildCalendar();

Is this really necessary though? Off-hand the conditions for rebuilding the calendar in _update() look like they should work here as well?

::: js/ui/dateMenu.js
@@ +421,3 @@
+        System.clearDateCaches();
+
+        this._calendar.updateTimeZone();

Does it make sense to propagate this to the messageList if the selected date was "today" before the timezone change?
Comment 28 Martin Andersson 2015-08-14 00:16:27 UTC
(In reply to Florian Müllner from comment #27)
> Review of attachment 302186 [details] [review] [review]:
> 
> ::: js/ui/calendar.js
> @@ +552,3 @@
>  
> +    updateTimeZone: function() {
> +        // The calendar need to be rebuilt after a time zone update beacuse
> 
> *because
Fixed
> 
> @@ +554,3 @@
> +        // The calendar need to be rebuilt after a time zone update beacuse
> +        // the date might have changed.
> +        this._rebuildCalendar();
> 
> Is this really necessary though? Off-hand the conditions for rebuilding the
> calendar in _update() look like they should work here as well?
It is necessary because _markedAsToday, which is compared against the now date to determine if the calendar should be rebuilt, is affected by the time zone change. Meaning that it changes with the time zone, so both dates will still be on the same day.
> 
> ::: js/ui/dateMenu.js
> @@ +421,3 @@
> +        System.clearDateCaches();
> +
> +        this._calendar.updateTimeZone();
> 
> Does it make sense to propagate this to the messageList if the selected date
> was "today" before the timezone change?
I'm not sure I fully understand. But if the user did not change the selected date (it is set to the date (and time) of the creation of the calendar) it will also change along with date. The reason for this is that the selected date is also affected by the time zone change. So if the date is the 13'th and the selected date is also the 13'th and a time zone change caused the date to become the 14'th the selected date will also be the 14'th.

However if the user changed the selected date the time is set to around 12 o'clock, which means that in this case the selected date will only change if the time zone difference is greater than 12 hours.

All this is bit confusing so it is entirely possible that I have got some details wrong.
Comment 29 Martin Andersson 2015-08-14 00:18:44 UTC
Created attachment 309237 [details] [review]
Rebuild the calendar after a time zone change
Comment 30 Martin Andersson 2015-08-14 00:24:19 UTC
I was using the time zone gui for triggering this bug. However I found that I could no longer trigger a timezone update event using the gui. I tracked down the issue and filed this bug.
https://bugzilla.gnome.org/show_bug.cgi?id=753602
Comment 31 Florian Müllner 2015-08-15 11:56:36 UTC
(In reply to Martin Andersson from comment #28)
> (In reply to Florian Müllner from comment #27)
> > Does it make sense to propagate this to the messageList if the selected date
> > was "today" before the timezone change?
> I'm not sure I fully understand. But if the user did not change the selected
> date (it is set to the date (and time) of the creation of the calendar) it
> will also change along with date.

What I mean is:
The message list contains an "Events" section that displays calendar events for the current (or selected) day. When the timezone changes, the list may change and thus requires a rebuild just as the calendar - or is there something I'm overlooking that makes it magically work?
Comment 32 Martin Andersson 2015-08-16 09:19:35 UTC
(In reply to Florian Müllner from comment #31)
> (In reply to Martin Andersson from comment #28)
> > (In reply to Florian Müllner from comment #27)
> > > Does it make sense to propagate this to the messageList if the selected date
> > > was "today" before the timezone change?
> > I'm not sure I fully understand. But if the user did not change the selected
> > date (it is set to the date (and time) of the creation of the calendar) it
> > will also change along with date.
> 
> What I mean is:
> The message list contains an "Events" section that displays calendar events
> for the current (or selected) day. When the timezone changes, the list may
> change and thus requires a rebuild just as the calendar - or is there
> something I'm overlooking that makes it magically work?

The "Events" section is also updated when the calendar is rebuilt due to a time zone change. So that already works as expected, however I don't know exactly what triggers that update.
Comment 33 Florian Müllner 2015-08-20 10:03:14 UTC
(In reply to Martin Andersson from comment #32)
> The "Events" section is also updated when the calendar is rebuilt due to a
> time zone change. So that already works as expected, however I don't know
> exactly what triggers that update.

The date for which events are shown is reset to "today" each time the calendar menu is opened - maybe it's that?
(Sorry, can't really test right now)
Comment 34 Iain Lane 2017-10-03 13:40:54 UTC
(In reply to Florian Müllner from comment #31)
> The message list contains an "Events" section that displays calendar events
> for the current (or selected) day. When the timezone changes, the list may
> change and thus requires a rebuild just as the calendar - or is there
> something I'm overlooking that makes it magically work?

I just noticed this in Ubuntu too. The bug is still present. I tried the patch and it works for me, including events being correct.

You can do something like this to reproduce / verify the patch.

  $ timedatectl set-timezone Europe/London
  $ timedatectl set-ntp false
  $ timedatectl set-time 01:00
  $ timedatectl set-timezone America/New_York # date changes to previous day

raise the calendar, click month forwards and backwards, days are offset by one or correct depending on whether you have this patch applied (there's a trivial conflict to resolve).

If possible it'd be great to have this patch in 3.26.1.
Comment 35 Florian Müllner 2017-10-04 14:44:54 UTC
Comment on attachment 309237 [details] [review]
Rebuild the calendar after a time zone change

Some nits in the commit message, otherwises looks good to me.
Comment 36 Jeremy Bicha 2017-10-25 16:25:30 UTC
*** Bug 765897 has been marked as a duplicate of this bug. ***