I am working on implementing Moment Timezone in a Django application to fix user access to it from different time zones, and I am launching an error when importing files through Require.js. time.js, moment-timezone.js and time-timezone-data.js are all loaded, but when my script starts and tries to initiate them, moment-moment zone.js and moment-time-data .js throw Unopened TypeErrors.
My time-timezone-data.js file is copied from the Moment.js time zone data generator and looks like this (although with more time zones):
moment.tz.add({ "zones": { "America/New_York": [ "-4:56:2 - LMT 1883_10_18_12_3_58 -4:56:2", "-5 US E%sT 1920 -5", "-5 NYC E%sT 1942 -5", "-5 US E%sT 1946 -5", "-5 NYC E%sT 1967 -5", "-5 US E%sT" ] }, "rules": { "US": [ "1918 1919 2 0 8 2 0 1 D", "1918 1919 9 0 8 2 0 0 S", "1942 1942 1 9 7 2 0 1 W", "1945 1945 7 14 7 23 1 1 P", "1945 1945 8 30 7 2 0 0 S", "1967 2006 9 0 8 2 0 0 S", "1967 1973 3 0 8 2 0 1 D", "1974 1974 0 6 7 2 0 1 D", "1975 1975 1 23 7 2 0 1 D", "1976 1986 3 0 8 2 0 1 D", "1987 2006 3 1 0 2 0 1 D", "2007 9999 2 8 0 2 0 1 D", "2007 9999 10 1 0 2 0 0 S" ], "NYC": [ "1920 1920 2 0 8 2 0 1 D", "1920 1920 9 0 8 2 0 0 S", "1921 1966 3 0 8 2 0 1 D", "1921 1954 8 0 8 2 0 0 S", "1955 1966 9 0 8 2 0 0 S" ] }, "links": {} });
The requireConfig file is configured as follows:
require = { paths: { "moment": ServerInfo.generateStaticPathFor("js/ext/moment/moment-with-langs"), "moment-timezone": ServerInfo.generateStaticPathFor("js/ext/moment/moment-timezone"), "moment-timezone-data": ServerInfo.generateStaticPathFor("js/ext/moment/moment-timezone-data") }, shim: { "moment-timezone-data": { "deps": ["moment-timezone"] } } };
Then I try to start Moment Timezone as follows:
define(["moment", "moment-timezone", "moment-timezone-data"], function(moment) { var thisMoment = moment().tz('America/New_York').startOf('day'); });
moment-timezone-data.js raises an Uncaught TypeError on "Unable to call the add method from undefined on line 1:
moment.tz.add({ ... });
moment-timezone.js gives the error message "Unable to use TypeError" from the rule "Unable to call the" undefined "method on line 308:
return [zone, zone.rule(mom, lastZone)];