-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
define(["moment-timezone"], function (moment) { | ||
moment.tz.add({ | ||
"zones": { | ||
"America/Toronto": [ | ||
"-5:17:32 - LMT 1895 -5:17:32", | ||
"-5 Canada E%sT 1919 -5", | ||
"-5 Toronto E%sT 1942_1_9_2 -5", | ||
"-5 Canada E%sT 1946 -5", | ||
"-5 Toronto E%sT 1974 -5", | ||
"-5 Canada E%sT" | ||
] | ||
}, | ||
"rules": { | ||
"Canada": [ | ||
"1918 1918 3 14 7 2 0 1 D", | ||
"1918 1918 9 27 7 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", | ||
"1974 1986 3 0 8 2 0 1 D", | ||
"1974 2006 9 0 8 2 0 0 S", | ||
"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" | ||
], | ||
"Toronto": [ | ||
"1919 1919 2 30 7 23:30 0 1 D", | ||
"1919 1919 9 26 7 0 0 0 S", | ||
"1920 1920 4 2 7 2 0 1 D", | ||
"1920 1920 8 26 7 0 0 0 S", | ||
"1921 1921 4 15 7 2 0 1 D", | ||
"1921 1921 8 15 7 2 0 0 S", | ||
"1922 1923 4 8 0 2 0 1 D", | ||
"1922 1926 8 15 0 2 0 0 S", | ||
"1924 1927 4 1 0 2 0 1 D", | ||
"1927 1932 8 0 8 2 0 0 S", | ||
"1928 1931 3 0 8 2 0 1 D", | ||
"1932 1932 4 1 7 2 0 1 D", | ||
"1933 1940 3 0 8 2 0 1 D", | ||
"1933 1933 9 1 7 2 0 0 S", | ||
"1934 1939 8 0 8 2 0 0 S", | ||
"1945 1946 8 0 8 2 0 0 S", | ||
"1946 1946 3 0 8 2 0 1 D", | ||
"1947 1949 3 0 8 0 0 1 D", | ||
"1947 1948 8 0 8 0 0 0 S", | ||
"1949 1949 10 0 8 0 0 0 S", | ||
"1950 1973 3 0 8 2 0 1 D", | ||
"1950 1950 10 0 8 2 0 0 S", | ||
"1951 1956 8 0 8 2 0 0 S", | ||
"1957 1973 9 0 8 2 0 0 S" | ||
] | ||
}, | ||
"links": {} | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
define(["moment", "moment-timezone", "ext/moment-timezone-data"], function (_moment, __, __) { | ||
// Always use America/Toronto as the timezone. | ||
return function() { | ||
return (_moment.apply(moment, Array.prototype.slice.apply(arguments)) | ||
.tz("America/Toronto")); | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
define( | ||
['rmc_backbone', 'ext/jquery', 'ext/underscore', 'ext/underscore.string', | ||
'ext/bootstrap', 'course', 'util', 'facebook', 'ext/moment'], | ||
'ext/bootstrap', 'course', 'util', 'facebook', | ||
'rmc_moment'], | ||
function(RmcBackbone, $, _, _s, _bootstrap, _course, _util, _facebook, moment) { | ||
|
||
// Cache a propery for a given instance. | ||
var instancePropertyCache = function(getter) { | ||
return _.memoize(getter, function() { | ||
return this.cid; | ||
}); | ||
}; | ||
var minutesSinceSod = function(date) { | ||
var dateMoment = moment(date); | ||
return dateMoment.diff(dateMoment.sod(), 'minutes'); | ||
return dateMoment.diff(dateMoment.clone().startOf('day'), 'minutes'); | ||
}; | ||
|
||
var isSameDay = function(firstDate, secondDate) { | ||
var firstMoment = moment(firstDate); | ||
var secondMoment = moment(secondDate); | ||
return firstMoment.sod().diff(secondMoment.sod()) === 0; | ||
return firstMoment.startOf('day').diff(secondMoment.startOf('day')) === 0; | ||
}; | ||
|
||
// TODO(mack): rename UserScheduleItem to match the backend | ||
|
@@ -30,21 +36,6 @@ function(RmcBackbone, $, _, _s, _bootstrap, _course, _util, _facebook, moment) { | |
term_id: '' | ||
}, | ||
|
||
initialize: function() { | ||
// Server time is UTC, but client's computer is some other timezone. | ||
// Adjust to their timezone by adding moment.zone(). | ||
// FIXME(Sandy): This will break for people not in the same timezone as | ||
// their university, but they might not be attending classes there anyway? | ||
|
||
// FIXME(david): This is bugging out on prod but not local | ||
//var timezoneShift = function(date) { | ||
// mDate = moment(date); | ||
// return mDate.add('minutes', mDate.zone()).toDate(); | ||
//}; | ||
//this.set('start_date', timezoneShift(this.get('start_date'))); | ||
//this.set('end_date', timezoneShift(this.get('end_date'))); | ||
}, | ||
|
||
referenceFields: { | ||
'course': ['course_id', _course.CourseCollection] | ||
}, | ||
|
@@ -62,13 +53,13 @@ function(RmcBackbone, $, _, _s, _bootstrap, _course, _util, _facebook, moment) { | |
(selfEnd >= otherStart && selfEnd <= otherEnd); | ||
}, | ||
|
||
startMinutes: function() { | ||
startMinutes: instancePropertyCache(function() { | ||
return minutesSinceSod(this.get('start_date')); | ||
}, | ||
}), | ||
|
||
endMinutes: function() { | ||
endMinutes: instancePropertyCache(function() { | ||
return minutesSinceSod(this.get('end_date')); | ||
} | ||
}) | ||
}); | ||
|
||
var ScheduleItemCollection = RmcBackbone.Collection.extend({ | ||
|
@@ -346,7 +337,7 @@ function(RmcBackbone, $, _, _s, _bootstrap, _course, _util, _facebook, moment) { | |
}, | ||
|
||
setBestWeek: function() { | ||
var startOfCurrWeek = moment().day(1).sod(); | ||
var startOfCurrWeek = moment().day(1).startOf('day'); | ||
|
||
// Find the closest week in the future with schedule items, or failing | ||
// that the closest week in the past with schedule items | ||
|
@@ -358,15 +349,15 @@ function(RmcBackbone, $, _, _s, _bootstrap, _course, _util, _facebook, moment) { | |
futureItems = _(futureItems).sortBy(function(item) { | ||
return moment(item.get('start_date')).unix(); | ||
}); | ||
this.setWeek(moment(futureItems[0].get('start_date')).clone().day(1).sod().toDate()); | ||
this.setWeek(moment(futureItems[0].get('start_date')).clone().day(1).startOf('day').toDate()); | ||
} else { | ||
var pastItems = this.get('schedule_items').filter(function(item) { | ||
return startOfCurrWeek.unix() > moment(item.get('start_date')).unix(); | ||
}); | ||
pastItems = _(pastItems).sortBy(function(item) { | ||
return moment(item.get('start_date')).unix(); | ||
}); | ||
this.setWeek(moment(pastItems[pastItems.length-1].get('start_date')).clone().day(1).sod().toDate()); | ||
this.setWeek(moment(pastItems[pastItems.length-1].get('start_date')).clone().day(1).startOf('day').toDate()); | ||
} | ||
}, | ||
|
||
|
@@ -389,7 +380,7 @@ function(RmcBackbone, $, _, _s, _bootstrap, _course, _util, _facebook, moment) { | |
var currMoment = moment(); | ||
|
||
// Start the week on the Monday of the current week | ||
this.setWeek(currMoment.day(1).sod().toDate()); | ||
this.setWeek(currMoment.day(1).startOf('day').toDate()); | ||
}, | ||
|
||
setNextWeek: function() { | ||
|
@@ -923,9 +914,15 @@ function(RmcBackbone, $, _, _s, _bootstrap, _course, _util, _facebook, moment) { | |
hasClassOnDay[weekdayMap[day]] = true; | ||
}); | ||
|
||
var timeFormats = ['YYYY-MM-DD h:mm A', 'MM/DD/YYYY h:mm A', 'DD/MM/YYYY H:mm']; | ||
var firstStartMoment = moment(startDateStr + " " + startTimeStr, timeFormats); | ||
var firstEndMoment = moment(startDateStr + " " + endTimeStr, timeFormats); | ||
// Once we have the date of the item, figure out what the TZ offset is, | ||
// then interpret the date using that offset | ||
var tzOffsetStr = moment(startDateStr, [ | ||
"YYYY-MM-DD", "MM/DD/YYYY", "DD/MM/YYYY" | ||
]).tz("America/Toronto").format("ZZ"); | ||
|
||
var timeFormats = ['YYYY-MM-DD h:mm A ZZ', 'MM/DD/YYYY h:mm A ZZ', 'DD/MM/YYYY H:mm ZZ']; | ||
var firstStartMoment = moment(startDateStr + " " + startTimeStr + " " + tzOffsetStr, timeFormats); | ||
var firstEndMoment = moment(startDateStr + " " + endTimeStr + " " + tzOffsetStr, timeFormats); | ||
|
||
// Time delta between start and end time, in milliseconds | ||
var timeDelta = firstEndMoment - firstStartMoment; | ||
|
@@ -948,6 +945,13 @@ function(RmcBackbone, $, _, _s, _bootstrap, _course, _util, _facebook, moment) { | |
prof_name: profName | ||
}); | ||
} | ||
// When this crosses a DST line, it only changes the date, not the time | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
divad12
Member
|
||
// | ||
// > moment("2013-11-02 15:00").add('days', 0).tz("America/Toronto").format() | ||
// "2013-11-02T18:00:00-04:00" | ||
// > moment("2013-11-02 15:00").add('days', 1).tz("America/Toronto").format() | ||
// "2013-11-03T18:00:00-05:00" | ||
// | ||
currMoment.add('days', 1); | ||
} | ||
return processedSlotItems; | ||
|
I wasn't going to comment on this, but I feel obligated to...
"it only changes the date" => "it changes only the date"
(but I'm not saying you need to actually go make the change :P)