// note: all values past the year are optional and will default to the lowest possible value.
// [year, month, day , hour, minute, second, millisecond]
export function configFromArray (config) {
- var i, date, input = [], currentDate, yearToUse;
+ var i, date, input = [], currentDate, expectedWeekday, yearToUse;
if (config._d) {
return;
}
config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
+ expectedWeekday = config._useUTC ? config._d.getUTCDay() : config._d.getDay();
+
// Apply timezone offset from input. The actual utcOffset can be changed
// with parseZone.
if (config._tzm != null) {
}
// check for mismatching day of week
- if (config._w && typeof config._w.d !== 'undefined' && config._w.d !== config._d.getDay()) {
+ if (config._w && typeof config._w.d !== 'undefined' && config._w.d !== expectedWeekday) {
getParsingFlags(config).weekdayMismatch = true;
}
}
assert.equal(moment.utc('2012-W01').format(), '2012-01-02T00:00:00Z', '2012 week 1 (1st Jan Sun)');
});
+test('parsing weekdays verifies the day', function (assert) {
+ // string with format
+ assert.ok(!moment('Wed 08-10-2017', 'ddd MM-DD-YYYY').isValid(), 'because day of week is incorrect for the date');
+ assert.ok(moment('Thu 08-10-2017', 'ddd MM-DD-YYYY').isValid(), 'because day of week is correct for the date');
+});
+
+test('parsing weekday on utc dates verifies day acccording to utc time', function (assert) {
+ assert.ok(moment.utc('Mon 03:59', 'ddd HH:mm').isValid(), 'Monday 03:59');
+});
+
+test('parsing weekday on local dates verifies day acccording to local time', function (assert) {
+ // this doesn't do much useful if you're not in the US or at least close to it
+ assert.ok(moment('Mon 03:59', 'ddd HH:mm').isValid(), 'Monday 03:59');
+});
+
+test('parsing weekday on utc dates with specified offsets verifies day acccording to that offset', function (assert) {
+ assert.ok(moment.utc('Mon 03:59 +12:00', 'ddd HH:mm Z', true).isValid(), 'Monday 03:59');
+});
+
+test('parsing weekday on local dates with specified offsets verifies day acccording to that offset', function (assert) {
+ // if you're in the US, these times will all be sometime Sunday, but they shoud parse as Monday
+ assert.ok(moment('Mon 03:59 +12:00', 'ddd HH:mm Z', true).isValid(), 'Monday 03:59');
+});
+
test('parsing week year/week/weekday (dow 1, doy 4)', function (assert) {
moment.locale('dow:1,doy:4', {week: {dow: 1, doy: 4}});
}
});
-test('mismatching day-of-week and date', function (assert) {
- // string with format
- assert.ok(!moment('Wed 08-10-2017', 'ddd MM-DD-YYYY').isValid(), 'because day of week is incorrect for the date');
- assert.ok(moment('Thu 08-10-2017', 'ddd MM-DD-YYYY').isValid(), 'because day of week is correct for the date');
-});
-
assert.equal(o.zone(), -15);
assert.equal(o.hour(), 0);
});
+
+test('parse zone with weekday on verifies day acccording to the offset', function (assert) {
+ test.expectedDeprecations();
+ assert.ok(moment.parseZone('Mon 03:59 +12:00', 'ddd HH:mm Z', true).isValid(), 'Monday 03:59');
+});