From: Iskren Chernev Date: Sat, 2 Nov 2013 18:06:38 +0000 (-0700) Subject: Fix calendar bug related to DST and zones X-Git-Tag: 2.5.0^2~2^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F1370%2Fhead;p=thirdparty%2Fmoment.git Fix calendar bug related to DST and zones We need the start of today, in either local time or utc (zone) time. We can not assume that local time is the same as utc (current zone), because that changes with DST. --- diff --git a/moment.js b/moment.js index 0e87facfe..b97dff98b 100644 --- a/moment.js +++ b/moment.js @@ -1868,13 +1868,16 @@ }, calendar : function () { - var diff = this.diff(moment().zone(this.zone()).startOf('day'), 'days', true), + // We want to compare the start of today, vs this. + // Getting start-of-today depends on whether we're zone'd or not. + var sod = (this._isUTC ? moment().zone(this.zone()) : moment()).startOf('day'), + diff = this.diff(sod, 'days', true), format = diff < -6 ? 'sameElse' : - diff < -1 ? 'lastWeek' : - diff < 0 ? 'lastDay' : - diff < 1 ? 'sameDay' : - diff < 2 ? 'nextDay' : - diff < 7 ? 'nextWeek' : 'sameElse'; + diff < -1 ? 'lastWeek' : + diff < 0 ? 'lastDay' : + diff < 1 ? 'sameDay' : + diff < 2 ? 'nextDay' : + diff < 7 ? 'nextWeek' : 'sameElse'; return this.format(this.lang().calendar(format, this)); },