| 1 | "use strict"; |
| 2 | |
| 3 | var moment = require("../../index"), |
| 4 | needsOffset = moment.tz.needsOffset; |
| 5 | |
| 6 | exports['needs-offset'] = { |
| 7 | 'Array' : function (t) { |
| 8 | t.ok(needsOffset(moment([2010, 0, 1])), 'Parsing an array needs an offset.'); |
| 9 | t.ok(needsOffset(moment.utc([2010, 0, 1])), 'Parsing an array needs an offset.'); |
| 10 | t.done(); |
| 11 | }, |
| 12 | |
| 13 | 'Now' : function (t) { |
| 14 | t.ok(!needsOffset(moment()), 'Parsing now does not need an offset.'); |
| 15 | t.ok(!needsOffset(moment.utc()), 'Parsing now does not need an offset.'); |
| 16 | t.done(); |
| 17 | }, |
| 18 | |
| 19 | 'String + Format' : function (t) { |
| 20 | t.ok(needsOffset(moment("Mar 4 2010", "MMM D YYYY")), 'Parsing a string and format needs an offset.'); |
| 21 | t.ok(needsOffset(moment.utc("Mar 4 2010", "MMM D YYYY")), 'Parsing a string and format needs an offset.'); |
| 22 | t.done(); |
| 23 | }, |
| 24 | |
| 25 | 'String + Timestamp Format': function(t) { |
| 26 | t.ok(!needsOffset(moment.utc("1267660800000", "x")), 'Parsing a string with timestamp format "x" does not need an offset.'); |
| 27 | t.ok(!needsOffset(moment.utc("1267660800", "X")), 'Parsing a string with timestamp format "X" does not need an offset.'); |
| 28 | t.done(); |
| 29 | }, |
| 30 | |
| 31 | 'String + Format + Offset' : function (t) { |
| 32 | t.ok(!needsOffset(moment("Mar 4 2010 +1000", "MMM D YYYY Z")), 'Parsing a string and format and offset does not need an offset.'); |
| 33 | t.ok(!needsOffset(moment.utc("Mar 4 2010 +1000", "MMM D YYYY Z")), 'Parsing a string and format and offset does not need an offset.'); |
| 34 | t.ok(!needsOffset(moment("Mar 4 2010 +10:00", "MMM D YYYY ZZ")), 'Parsing a string and format and offset does not need an offset.'); |
| 35 | t.ok(!needsOffset(moment.utc("Mar 4 2010 +10:00", "MMM D YYYY ZZ")), 'Parsing a string and format and offset does not need an offset.'); |
| 36 | t.done(); |
| 37 | }, |
| 38 | |
| 39 | 'String + Formats' : function (t) { |
| 40 | var formats = ["YYYY-MM-DD", "MMM D YYYY"]; |
| 41 | t.ok(needsOffset(moment("Mar 4 2010", formats)), 'Parsing a string and formats needs an offset.'); |
| 42 | t.ok(needsOffset(moment.utc("Mar 4 2010", formats)), 'Parsing a string and formats needs an offset.'); |
| 43 | t.done(); |
| 44 | }, |
| 45 | |
| 46 | 'String + Timestamp Formats': function(t) { |
| 47 | var formats = ["x", "X", "MMM D YYYY"]; |
| 48 | t.ok(!needsOffset(moment.utc("1267660800000", formats)), 'Parsing a string with timestamp format "x" does not need an offset.'); |
| 49 | t.ok(!needsOffset(moment.utc("1267660800", formats)), 'Parsing a string with timestamp format "X" does not need an offset.'); |
| 50 | t.ok(needsOffset(moment("Mar 4 2010", formats)), 'Parsing a string and formats needs an offset.'); |
| 51 | t.done(); |
| 52 | }, |
| 53 | |
| 54 | 'ISO 8601 String' : function (t) { |
| 55 | t.ok(needsOffset(moment("2011-10-10 10:10:10")), 'Parsing an ISO 8601 string without an offset needs an offset.'); |
| 56 | t.ok(needsOffset(moment.utc("2011-10-10 10:10:10")), 'Parsing an ISO 8601 string without an offset needs an offset.'); |
| 57 | t.ok(!needsOffset(moment("2011-10-10 10:10:10+10:00")), 'Parsing an ISO 8601 string with an offset does not need an offset.'); |
| 58 | t.ok(!needsOffset(moment.utc("2011-10-10 10:10:10+10:00")), 'Parsing an ISO 8601 string with an offset does not need an offset.'); |
| 59 | t.ok(!needsOffset(moment("2011-10-10 10:10:10+00:00")), 'Parsing an ISO 8601 string with an offset does not need an offset.'); |
| 60 | t.ok(!needsOffset(moment.utc("2011-10-10 10:10:10+00:00")), 'Parsing an ISO 8601 string with an offset does not need an offset.'); |
| 61 | t.done(); |
| 62 | }, |
| 63 | |
| 64 | 'Object' : function (t) { |
| 65 | t.ok(needsOffset(moment({y : 2010, M : 3, d : 1})), 'Parsing an object needs an offset.'); |
| 66 | t.ok(needsOffset(moment({year : 2010, month : 3, day : 1})), 'Parsing an object needs an offset.'); |
| 67 | t.ok(needsOffset(moment.utc({y : 2010, M : 3, d : 1})), 'Parsing an object needs an offset.'); |
| 68 | t.done(); |
| 69 | }, |
| 70 | |
| 71 | 'Unix Offset' : function (t) { |
| 72 | t.ok(!needsOffset(moment(1318781876406)), 'Parsing unix timestamp in milliseconds does not need an offset.'); |
| 73 | t.ok(!needsOffset(moment.utc(1318781876406)), 'Parsing unix timestamp in milliseconds does not need an offset.'); |
| 74 | t.done(); |
| 75 | }, |
| 76 | |
| 77 | 'Unix Timestamp' : function (t) { |
| 78 | t.ok(!needsOffset(moment.unix(1318781876)), 'Parsing unix timestamp in seconds does not need an offset.'); |
| 79 | t.done(); |
| 80 | }, |
| 81 | |
| 82 | 'Date' : function (t) { |
| 83 | t.ok(!needsOffset(moment(new Date())), 'Parsing a date object does not need an offset.'); |
| 84 | t.ok(!needsOffset(moment.utc(new Date())), 'Parsing a date object does not need an offset.'); |
| 85 | t.done(); |
| 86 | } |
| 87 | }; |