]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Making a default format for moment.fn.format
authorTim Wood <washwithcare@gmail.com>
Mon, 20 Feb 2012 19:03:42 +0000 (11:03 -0800)
committerTim Wood <washwithcare@gmail.com>
Mon, 20 Feb 2012 20:40:56 +0000 (12:40 -0800)
#121 Default format is 'YYYY-MM-DDTHH:mm:ssZ'

moment.js
test/moment/format.js

index 4524e24005ab079169c866bf260a33d18bfbce7d..ce3e0d913fac87bb111b90b3c4e063b73714c99b 100644 (file)
--- a/moment.js
+++ b/moment.js
@@ -18,6 +18,7 @@
         timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g,
         tokenCharacters = /(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g,
         inputCharacters = /(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi,
+        isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
         timezoneParseRegex = /([\+\-]|\d\d)/gi,
         VERSION = "1.4.0",
         shortcuts = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|');
     // version number
     moment.version = VERSION;
 
+    // default format
+    moment.defaultFormat = isoFormat;
+
     // language switching and caching
     moment.lang = function (key, values) {
         var i,
         },
 
         format : function (inputString) {
-            return formatDate(this._d, inputString);
+            return inputString ? formatDate(this._d, inputString) :
+                formatDate(this._d, moment.defaultFormat);
         },
 
         add : function (input, val) {
index 1b656dc8710e010ce904e75c16b57e808d1d63b7..1459a2ebfeba311e423da47de19dbe5718d4a09b 100644 (file)
@@ -81,5 +81,12 @@ exports.format = {
         test.ok(moment().zone() % 30 === 0, 'moment.fn.zone should be a multiple of 30 (was ' + moment().zone() + ')');
         test.equal(moment().zone(), new Date().getTimezoneOffset(), 'zone should equal getTimezoneOffset');
         test.done();
+    },
+
+    "default format" : function(test) {
+        test.expect(1);
+        var isoRegex = /\d{4}.\d\d.\d\dT\d\d.\d\d.\d\d[\+\-]\d\d:\d\d/;
+        test.ok(isoRegex.exec(moment().format()), "default format (" + moment().format() + ") should match ISO");
+        test.done();
     }
 };