]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixing backwards timezones and updating tests #139
authorTim Wood <washwithcare@gmail.com>
Mon, 30 Jan 2012 16:36:57 +0000 (08:36 -0800)
committerTim Wood <washwithcare@gmail.com>
Mon, 30 Jan 2012 16:36:57 +0000 (08:36 -0800)
moment.js
sitesrc/js/unit-tests.js

index 9a93b5d62c44c745e6ac190b6b76c01439cc9d94..ac41f2f89eb1c35ef0ade440b6c996c7b66de18e 100644 (file)
--- a/moment.js
+++ b/moment.js
@@ -94,7 +94,7 @@
             currentHours = m.hours(),
             currentMinutes = m.minutes(),
             currentSeconds = m.seconds(),
-            currentZone = m.zone(),
+            currentZone = -m.zone(),
             ordinal = moment.ordinal,
             meridiem = moment.meridiem;
         // check if the character is a format
                     timezoneMinutes = ~~a[2];
                 }
                 // reverse offsets
-                if (a[0] === '-') {
+                if (a[0] === '+') {
                     timezoneHours = -timezoneHours;
                     timezoneMinutes = -timezoneMinutes;
                 }
index 921c67c7209433e8fac125c2cc136583ee0aef43..c1ee6a27d1ceb966aa3c2d2524f540937868da9d 100755 (executable)
@@ -98,23 +98,23 @@ test("string with format", 23, function() {
 });
 
 test("string with format (timezone)", 8, function() {
-    equal(moment('5 +0700', 'H ZZ').native().getUTCHours(), 12, 'parse hours "5 +0700" ---> "H ZZ"');
-    equal(moment('5 +07:00', 'H Z').native().getUTCHours(), 12, 'parse hours "5 +07:00" ---> "H Z"');
-    equal(moment('5 +0730', 'H ZZ').native().getUTCMinutes(), 30, 'parse hours "5 +0730" ---> "H ZZ"');
-    equal(moment('5 +07:30', 'H Z').native().getUTCMinutes(), 30, 'parse hours "5 +07:30" ---> "H Z"');
-    equal(moment('5 -0100', 'H ZZ').native().getUTCHours(), 4, 'parse hours "5 -0100" ---> "H ZZ"');
-    equal(moment('5 -01:00', 'H Z').native().getUTCHours(), 4, 'parse hours "5 -01:00" ---> "H Z"');
-    equal(moment('5 -0130', 'H ZZ').native().getUTCMinutes(), 30, 'parse hours "5 -0130" ---> "H ZZ"');
-    equal(moment('5 -01:30', 'H Z').native().getUTCMinutes(), 30, 'parse hours "5 -01:30" ---> "H Z"');
+    equal(moment('5 -0700', 'H ZZ').native().getUTCHours(), 12, 'parse hours "5 -0700" ---> "H ZZ"');
+    equal(moment('5 -07:00', 'H Z').native().getUTCHours(), 12, 'parse hours "5 -07:00" ---> "H Z"');
+    equal(moment('5 -0730', 'H ZZ').native().getUTCMinutes(), 30, 'parse hours "5 -0730" ---> "H ZZ"');
+    equal(moment('5 -07:30', 'H Z').native().getUTCMinutes(), 30, 'parse hours "5 -07:30" ---> "H Z"');
+    equal(moment('5 +0100', 'H ZZ').native().getUTCHours(), 4, 'parse hours "5 +0100" ---> "H ZZ"');
+    equal(moment('5 +01:00', 'H Z').native().getUTCHours(), 4, 'parse hours "5 +01:00" ---> "H Z"');
+    equal(moment('5 +0130', 'H ZZ').native().getUTCMinutes(), 30, 'parse hours "5 +0130" ---> "H ZZ"');
+    equal(moment('5 +01:30', 'H Z').native().getUTCMinutes(), 30, 'parse hours "5 +01:30" ---> "H Z"');
 });
 
 test("string with format (timezone offset)", 3, function() {
     var a = new Date(Date.UTC(2011, 0, 1, 1));
-    var b = moment('2011 1 1 0 +01:00', 'YYYY MM DD HH Z');
+    var b = moment('2011 1 1 0 -01:00', 'YYYY MM DD HH Z');
     equal(a.getHours(), b.hours(), 'date created with utc == parsed string with timezone offset');
     equal(+a, +b, 'date created with utc == parsed string with timezone offset');
-    var c = moment('2011 2 1 10 +05:00', 'YYYY MM DD HH Z');
-    var d = moment('2011 2 1 8 +07:00', 'YYYY MM DD HH Z');
+    var c = moment('2011 2 1 10 -05:00', 'YYYY MM DD HH Z');
+    var d = moment('2011 2 1 8 -07:00', 'YYYY MM DD HH Z');
     equal(c.hours(), d.hours(), '10 am central time == 8 am pacific time');
 });
 
@@ -431,7 +431,16 @@ test("isDST", 2, function() {
     ok(b.isDST(), 'March 14 2011 is DST (Note: this unit test should fail if your timezone does not have Daylight Savings Time)');
 });
 
-test("zone", 2, function() {
+test("zone", 3, function() {
+    if (moment().zone() > 0) {
+        ok(moment().format('ZZ').indexOf('-') > -1, 'When the zone() offset is greater than 0, the ISO offset should be less than zero');
+    }
+    if (moment().zone() < 0) {
+        ok(moment().format('ZZ').indexOf('+') > -1, 'When the zone() offset is less than 0, the ISO offset should be greater than zero');
+    }
+    if (moment().zone() == 0) {
+        ok(moment().format('ZZ').indexOf('+') > -1, 'When the zone() offset is equal to 0, the ISO offset should be positive zero');
+    }
     ok(moment().zone() % 30 === 0, 'moment.fn.zone should be a multiple of 30 (was ' + moment().zone() + ')');
     equal(moment().zone(), new Date().getTimezoneOffset(), 'zone should equal getTimezoneOffset');
 });