From bd280ada8465fe27858da70627d15d7130406e48 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Sat, 2 Nov 2013 11:06:38 -0700 Subject: [PATCH] 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. --- moment.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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)); }, -- 2.47.2