]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Respect timezone settings for .calendar() format
authorbentaber <ben.taber@gmail.com>
Thu, 22 Aug 2013 04:03:33 +0000 (22:03 -0600)
committerbentaber <ben.taber@gmail.com>
Thu, 22 Aug 2013 04:03:33 +0000 (22:03 -0600)
Fixes #946

moment.js
test/moment/preparse_postformat.js

index 03d66a4e02e82602d7467ffd5ca388f0e6ed97ea..04fec06dfb60b410dd5f540fca9e6e43d95addbc 100644 (file)
--- a/moment.js
+++ b/moment.js
         },
 
         calendar : function () {
-            var diff = this.diff(moment().startOf('day'), 'days', true),
+            var diff = this.diff(moment().zone(this.zone()).startOf('day'), 'days', true),
                 format = diff < -6 ? 'sameElse' :
                 diff < -1 ? 'lastWeek' :
                 diff < 0 ? 'lastDay' :
index b7dd8f1ce7204fc676677a2c086f751a2cb99c54..cf969068dd4db8267fd4d029f55e07d2531ba72c 100644 (file)
@@ -86,6 +86,16 @@ exports.preparse_postformat = {
         test.equal(moment(a).subtract({ h: 1 }).calendar(),  "Today at !:)) AM",     "Now minus 1 hour");
         test.equal(moment(a).subtract({ d: 1 }).calendar(),  "Yesterday at @:)) AM", "yesterday at the same time");
 
+        test.done();
+    },
+
+    "calendar day timezone" : function (test) {
+        test.expect(1);
+
+        var z = 60,
+            a = moment().zone(z).startOf('day').subtract({ m: 1 });
+
+        test.equal(moment(a).zone(z).calendar(), "Yesterday at !!:%( PM", "Yesterday at 11:59 PM");
         test.done();
     }
 };