function makeDateFromStringAndFormat(config) {
if (config._f === moment.ISO_8601) {
- makeDateFromString(config, false);
+ parseISO(config);
return;
}
}
// date from iso format
- function makeDateFromString(config, useFallback) {
+ function parseISO(config) {
var i, l,
string = config._i,
match = isoRegex.exec(string);
- useFallback = typeof useFallback === 'undefined' ? true : useFallback;
-
if (match) {
config._pf.iso = true;
for (i = 0, l = isoDates.length; i < l; i++) {
config._f += "Z";
}
makeDateFromStringAndFormat(config);
+ } else {
+ config._isValid = false;
}
- else {
- if (useFallback) {
- moment.createFromInputFallback(config);
- } else {
- config._isValid = false;
- }
+ }
+
+ // date from iso format or fallback
+ function makeDateFromString(config) {
+ parseISO(config);
+ if (config._isValid === false) {
+ delete config._isValid;
+ moment.createFromInputFallback(config);
}
}
moment.defaultFormat = isoFormat;
// constant that refers to the ISO standard
- moment.ISO_8601 = 'ISO 8601';
+ moment.ISO_8601 = function () {};
// Plugins that add properties should also add the key here (null value),
// so we can properly clone ourselves.
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, [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']);
- }
- test.equal(parseISO('1994')._f, 'YYYY', 'iso: test parse YYYY');
- test.equal(parseISO('17:15')._f, 'HH:mm', 'iso: test parse HH:mm');
- test.equal(parseISO('06')._f, 'MM', 'iso: test parse MM');
- test.equal(parseISO('2012-06-01')._pf.iso, true, 'iso: test parse iso');
-
- test.equal(moment('2014-05-05', [moment.ISO_8601, 'YYYY-MM-DD'])._pf.iso, true, 'iso: edge case array precedence iso');
- test.equal(moment('2014-05-05', ['YYYY-MM-DD', moment.ISO_8601])._pf.iso, false, 'iso: edge case array precedence not iso');
+ test.done();
+ },
+ "string with array of formats + ISO": function (test) {
+ test.equal(moment('1994', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).year(), 1994, 'iso: test parse YYYY');
+ test.equal(moment('17:15', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).hour(), 17, 'iso: test parse HH:mm (1)');
+ test.equal(moment('17:15', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).minutes(), 15, 'iso: test parse HH:mm (2)');
+ test.equal(moment('06', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).month(), 6-1, 'iso: test parse MM');
+ test.equal(moment('2012-06-01', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).parsingFlags().iso, true, 'iso: test parse iso');
+ test.equal(moment('2014-05-05', [moment.ISO_8601, 'YYYY-MM-DD']).parsingFlags().iso, true, 'iso: edge case array precedence iso');
+ test.equal(moment('2014-05-05', ['YYYY-MM-DD', moment.ISO_8601]).parsingFlags().iso, false, 'iso: edge case array precedence not iso');
test.done();
},