]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix calendar bug related to DST and zones 1370/head
authorIskren Chernev <iskren.chernev@gmail.com>
Sat, 2 Nov 2013 18:06:38 +0000 (11:06 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Sat, 2 Nov 2013 18:06:38 +0000 (11:06 -0700)
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

index 0e87facfe8bb4f6af161d529988cb7c514efca03..b97dff98b968d9c6cd558f098cf89ea278d9485c 100644 (file)
--- a/moment.js
+++ b/moment.js
         },
 
         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));
         },