]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Allow ISO-8601 to be passed as a format.
authorSimon Bernier St-Pierre <sbernierstpierre@gmail.com>
Tue, 3 Jun 2014 15:27:27 +0000 (11:27 -0400)
committerSimon Bernier St-Pierre <sbernierstpierre@gmail.com>
Tue, 3 Jun 2014 15:42:32 +0000 (11:42 -0400)
This commit allows the ISO-8601 format to be
passed as a format in the moment(string, array)
constructor. This is a preliminary commit as this
addition as yielded a few issues.

moment.js
test/moment/create.js

index 07448344c8956853eee889e7fc3a6e7d9cfaa0e6..022f4c161c3a2799bcb04600b6b3d9ff8a3aedec 100644 (file)
--- a/moment.js
+++ b/moment.js
     // date from string and format string
     function makeDateFromStringAndFormat(config) {
 
+        if (config._f === moment.ISO_8601) {
+            makeDateFromString(config);
+            return;
+        }
+
         config._a = [];
         config._pf.empty = true;
 
     // default format
     moment.defaultFormat = isoFormat;
 
+    // constant that refers to the ISO standard
+    moment.ISO_8601 = 'ISO 8601';
+
     // Plugins that add properties should also add the key here (null value),
     // so we can properly clone ourselves.
     moment.momentProperties = momentProperties;
index 9947d485614a74e48285d952ab9d064b53350684..f67db1c2373184eb7d70504ad190ff46f8216396 100644 (file)
@@ -395,6 +395,16 @@ exports.create = {
 
         test.equal(moment('01', ["MM", "DD"])._f, "MM", "Should use first valid format");
 
+        // pass an ISO date in the array of formats
+        function parseISO(string) {
+            return moment(string, ['YYYY', 'HH:mm', 'M', moment.ISO_8601]);
+        }
+        // those tests are broken because of the scoring system
+        // and the deprecation of createFromInputFallback
+        //test.equal(parseISO('1994').year(), 1994, 'iso: test parse year');
+        //test.equal(parseISO('17:15').format('HH:mm'), '17:15', 'iso: test parse HH:mm');
+        test.equal(parseISO('2012-06-01').format('YYYY-MM-DD'), '2012-06-01', 'iso: test parse iso');
+
         test.done();
     },