Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Fix inter-timezone schedule problems with moment-timezone #19

Merged
merged 4 commits into from
Nov 18, 2013

Conversation

jlfwong
Copy link
Member

@jlfwong jlfwong commented Nov 17, 2013

The way this works is by using the rmc_moment file instead of moment as a shim to always ensure that the timezone "America/Toronto" is set.

Testing steps:

  1. Change your system timezone to America/Toronto
  2. Load localhost in tab 1 in Chrome
  3. Change your system timezone to America/Los_Angeles
  4. Load localhost in tab 2 in Chrome. Chrome (at least for me) only updates pages timezones when a new tab is created. This means you can refresh the tab 1 when your system time is America/Los_Angeles, and the tab will still be in America/Toronto

Upload schedule in Tab 1. Schedule should look right.
Reload Tab 2. Schedule should be fine.
Upload schedule in Tab 2. Schedule should look right.
Reload Tab 1. Schedule should be fine.

This unfortunately still adds about 400-500ms to the page load time for me because of the moment-timezone perf problems. I added to an existing issue here: moment/moment-timezone#44 and am going to try to look into myself.

We also need to figure out a sensible way of doing a backfill for this to fix all the schedules uploaded outside of America/Toronto (all the ones inside there should be fine).

This also version bumps moment to 2.4.0, and switches to unminified source. When we compress to send things up to prod, I believe we compress them all anyway - and this made profiling much much easier.

@@ -0,0 +1,16 @@
define(["moment-timezone"], function (moment) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might notice that this is an incomplete data set for the America/Toronto timezone. This is intentional, as it speeds up checking which timezone "rule" applies. We don't care about any dates before 2007, so this should be fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clever solution on the part of Moment to not require loading up a huge data file on the client side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind commenting the URL where you can generate this file? ie. http://momentjs.com/timezone/data/

@divad12
Copy link
Member

divad12 commented Nov 17, 2013

I briefly looked at this, but this LGTM.

Thanks for dealing with all this timezone crap!! This is great stuff.

@@ -0,0 +1,8 @@
define(["moment", "moment-timezone", "ext/moment-timezone-data"], function (_moment, __, __) {
// Always use America/Toronto as the timezone.
return function rmc_moment(a, b, c, d) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool syntax to avoid leaving anonymous functions nameless. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Makes it more useful in stack traces and in profiling.

@mduan
Copy link
Contributor

mduan commented Nov 17, 2013

Thanks! This is nice, and today I learned about _.debounce() and _.memoize().

return _moment(a, b, c, d)
.tz("America/Toronto");
}
rmcMoment.tz = _moment.tz;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about doing a _.extend here to ensure we bring in all the static methods?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eg. if someone tries to call moment.isMoment they might be confused wondering why it doesn't work....

All of the following should work now:

Upload in America/Los_Angeles, view in America/Toronto
Upload in America/Toronto, view in America/Toronto
Upload in America/Los_Angeles, view in America/Los_Angeles
Upload in America/Toronto, view in America/Los_Angeles

Also updates to Moment.js 2.4.0
jlfwong added a commit that referenced this pull request Nov 18, 2013
Fix inter-timezone schedule problems with moment-timezone
@jlfwong jlfwong merged commit a289954 into master Nov 18, 2013
@jlfwong jlfwong deleted the jlfwong-moment-tz branch November 18, 2013 03:07
@jswu
Copy link
Member

jswu commented Nov 18, 2013

W00t, Finally rid of that annoying timezone issue. Thanks!

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

Successfully merging this pull request may close these issues.

4 participants