diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-10-14 18:40:54 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-10-14 18:40:54 +0200 |
commit | 9df98e65f842cf3acae09cbdd969966f42d64469 (patch) | |
tree | f071d3e09a342c208fb8e1cd3f5241d64fbfbaf3 /node_modules/moment/src/lib | |
parent | 008926b18470e7f394cd640302957b29728a9803 (diff) |
update dependencies
Diffstat (limited to 'node_modules/moment/src/lib')
-rw-r--r-- | node_modules/moment/src/lib/create/from-array.js | 5 | ||||
-rw-r--r-- | node_modules/moment/src/lib/create/from-string.js | 142 | ||||
-rw-r--r-- | node_modules/moment/src/lib/create/valid.js | 1 | ||||
-rw-r--r-- | node_modules/moment/src/lib/duration/clone.js | 6 | ||||
-rw-r--r-- | node_modules/moment/src/lib/duration/constructor.js | 2 | ||||
-rw-r--r-- | node_modules/moment/src/lib/duration/create.js | 6 | ||||
-rw-r--r-- | node_modules/moment/src/lib/duration/iso-string.js | 26 | ||||
-rw-r--r-- | node_modules/moment/src/lib/duration/prototype.js | 2 | ||||
-rw-r--r-- | node_modules/moment/src/lib/duration/valid.js | 3 | ||||
-rw-r--r-- | node_modules/moment/src/lib/locale/locales.js | 7 | ||||
-rw-r--r-- | node_modules/moment/src/lib/moment/add-subtract.js | 8 | ||||
-rw-r--r-- | node_modules/moment/src/lib/moment/diff.js | 26 | ||||
-rw-r--r-- | node_modules/moment/src/lib/moment/get-set.js | 12 | ||||
-rw-r--r-- | node_modules/moment/src/lib/units/month.js | 9 | ||||
-rw-r--r-- | node_modules/moment/src/lib/units/year.js | 2 | ||||
-rw-r--r-- | node_modules/moment/src/lib/utils/is-object-empty.js | 15 | ||||
-rw-r--r-- | node_modules/moment/src/lib/utils/mod.js | 3 |
17 files changed, 171 insertions, 104 deletions
diff --git a/node_modules/moment/src/lib/create/from-array.js b/node_modules/moment/src/lib/create/from-array.js index 0cdf474cf..7626c455d 100644 --- a/node_modules/moment/src/lib/create/from-array.js +++ b/node_modules/moment/src/lib/create/from-array.js @@ -80,6 +80,11 @@ export function configFromArray (config) { if (config._nextDay) { config._a[HOUR] = 24; } + + // check for mismatching day of week + if (config._w && typeof config._w.d !== 'undefined' && config._w.d !== config._d.getDay()) { + getParsingFlags(config).weekdayMismatch = true; + } } function dayOfYearFromWeekInfo(config) { diff --git a/node_modules/moment/src/lib/create/from-string.js b/node_modules/moment/src/lib/create/from-string.js index 7cae76d70..7c1052a3e 100644 --- a/node_modules/moment/src/lib/create/from-string.js +++ b/node_modules/moment/src/lib/create/from-string.js @@ -1,7 +1,11 @@ import { configFromStringAndFormat } from './from-string-and-format'; +import { createUTCDate } from './date-from-array'; +import { configFromArray } from './from-array'; import { hooks } from '../utils/hooks'; import { deprecate } from '../utils/deprecate'; import getParsingFlags from './parsing-flags'; +import {defaultLocaleMonthsShort} from '../units/month'; +import {defaultLocaleWeekdaysShort} from '../units/day-of-week'; // iso 8601 regex // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00) @@ -94,70 +98,94 @@ export function configFromISO(config) { } // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3 -var basicRfcRegex = /^((?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d?\d\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(?:\d\d)?\d\d\s)(\d\d:\d\d)(\:\d\d)?(\s(?:UT|GMT|[ECMP][SD]T|[A-IK-Za-ik-z]|[+-]\d{4}))$/; +var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/; + +function extractFromRFC2822Strings(yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) { + var result = [ + untruncateYear(yearStr), + defaultLocaleMonthsShort.indexOf(monthStr), + parseInt(dayStr, 10), + parseInt(hourStr, 10), + parseInt(minuteStr, 10) + ]; + + if (secondStr) { + result.push(parseInt(secondStr, 10)); + } -// date and time from ref 2822 format -export function configFromRFC2822(config) { - var string, match, dayFormat, - dateFormat, timeFormat, tzFormat; - var timezones = { - ' GMT': ' +0000', - ' EDT': ' -0400', - ' EST': ' -0500', - ' CDT': ' -0500', - ' CST': ' -0600', - ' MDT': ' -0600', - ' MST': ' -0700', - ' PDT': ' -0700', - ' PST': ' -0800' - }; - var military = 'YXWVUTSRQPONZABCDEFGHIKLM'; - var timezone, timezoneIndex; - - string = config._i - .replace(/\([^\)]*\)|[\n\t]/g, ' ') // Remove comments and folding whitespace - .replace(/(\s\s+)/g, ' ') // Replace multiple-spaces with a single space - .replace(/^\s|\s$/g, ''); // Remove leading and trailing spaces - match = basicRfcRegex.exec(string); + return result; +} - if (match) { - dayFormat = match[1] ? 'ddd' + ((match[1].length === 5) ? ', ' : ' ') : ''; - dateFormat = 'D MMM ' + ((match[2].length > 10) ? 'YYYY ' : 'YY '); - timeFormat = 'HH:mm' + (match[4] ? ':ss' : ''); +function untruncateYear(yearStr) { + var year = parseInt(yearStr, 10); + if (year <= 49) { + return 2000 + year; + } else if (year <= 999) { + return 1900 + year; + } + return year; +} - // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check. - if (match[1]) { // day of week given - var momentDate = new Date(match[2]); - var momentDay = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][momentDate.getDay()]; +function preprocessRFC2822(s) { + // Remove comments and folding whitespace and replace multiple-spaces with a single space + return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').trim(); +} - if (match[1].substr(0,3) !== momentDay) { - getParsingFlags(config).weekdayMismatch = true; - config._isValid = false; - return; - } +function checkWeekday(weekdayStr, parsedInput, config) { + if (weekdayStr) { + // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check. + var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr), + weekdayActual = new Date(parsedInput[0], parsedInput[1], parsedInput[2]).getDay(); + if (weekdayProvided !== weekdayActual) { + getParsingFlags(config).weekdayMismatch = true; + config._isValid = false; + return false; } + } + return true; +} - switch (match[5].length) { - case 2: // military - if (timezoneIndex === 0) { - timezone = ' +0000'; - } else { - timezoneIndex = military.indexOf(match[5][1].toUpperCase()) - 12; - timezone = ((timezoneIndex < 0) ? ' -' : ' +') + - (('' + timezoneIndex).replace(/^-?/, '0')).match(/..$/)[0] + '00'; - } - break; - case 4: // Zone - timezone = timezones[match[5]]; - break; - default: // UT or +/-9999 - timezone = timezones[' GMT']; +var obsOffsets = { + UT: 0, + GMT: 0, + EDT: -4 * 60, + EST: -5 * 60, + CDT: -5 * 60, + CST: -6 * 60, + MDT: -6 * 60, + MST: -7 * 60, + PDT: -7 * 60, + PST: -8 * 60 +}; + +function calculateOffset(obsOffset, militaryOffset, numOffset) { + if (obsOffset) { + return obsOffsets[obsOffset]; + } else if (militaryOffset) { + // the only allowed military tz is Z + return 0; + } else { + var hm = parseInt(numOffset, 10); + var m = hm % 100, h = (hm - m) / 100; + return h * 60 + m; + } +} + +// date and time from ref 2822 format +export function configFromRFC2822(config) { + var match = rfc2822.exec(preprocessRFC2822(config._i)); + if (match) { + var parsedArray = extractFromRFC2822Strings(match[4], match[3], match[2], match[5], match[6], match[7]); + if (!checkWeekday(match[1], parsedArray, config)) { + return; } - match[5] = timezone; - config._i = match.splice(1).join(''); - tzFormat = ' ZZ'; - config._f = dayFormat + dateFormat + timeFormat + tzFormat; - configFromStringAndFormat(config); + + config._a = parsedArray; + config._tzm = calculateOffset(match[8], match[9], match[10]); + + config._d = createUTCDate.apply(null, config._a); + config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm); + getParsingFlags(config).rfc2822 = true; } else { config._isValid = false; diff --git a/node_modules/moment/src/lib/create/valid.js b/node_modules/moment/src/lib/create/valid.js index 96b1cf615..d13f12f8b 100644 --- a/node_modules/moment/src/lib/create/valid.js +++ b/node_modules/moment/src/lib/create/valid.js @@ -14,6 +14,7 @@ export function isValid(m) { !flags.empty && !flags.invalidMonth && !flags.invalidWeekday && + !flags.weekdayMismatch && !flags.nullInput && !flags.invalidFormat && !flags.userInvalidated && diff --git a/node_modules/moment/src/lib/duration/clone.js b/node_modules/moment/src/lib/duration/clone.js new file mode 100644 index 000000000..56008d12e --- /dev/null +++ b/node_modules/moment/src/lib/duration/clone.js @@ -0,0 +1,6 @@ +import { createDuration } from './create'; + +export function clone () { + return createDuration(this); +} + diff --git a/node_modules/moment/src/lib/duration/constructor.js b/node_modules/moment/src/lib/duration/constructor.js index 5c97ef108..2d86d5e2c 100644 --- a/node_modules/moment/src/lib/duration/constructor.js +++ b/node_modules/moment/src/lib/duration/constructor.js @@ -25,7 +25,7 @@ export function Duration (duration) { // day when working around DST, we need to store them separately this._days = +days + weeks * 7; - // It is impossible translate months into days without knowing + // It is impossible to translate months into days without knowing // which months you are are talking about, so we have to store // it separately. this._months = +months + diff --git a/node_modules/moment/src/lib/duration/create.js b/node_modules/moment/src/lib/duration/create.js index 9b6d5a964..346814816 100644 --- a/node_modules/moment/src/lib/duration/create.js +++ b/node_modules/moment/src/lib/duration/create.js @@ -9,12 +9,12 @@ import { createLocal } from '../create/local'; import { createInvalid as invalid } from './valid'; // ASP.NET json date format regex -var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/; +var aspNetRegex = /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/; // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere // and further modified to allow for strings containing both week and day -var isoRegex = /^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/; +var isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/; export function createDuration (input, key) { var duration = input, @@ -48,7 +48,7 @@ export function createDuration (input, key) { ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match }; } else if (!!(match = isoRegex.exec(input))) { - sign = (match[1] === '-') ? -1 : 1; + sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1; duration = { y : parseIso(match[2], sign), M : parseIso(match[3], sign), diff --git a/node_modules/moment/src/lib/duration/iso-string.js b/node_modules/moment/src/lib/duration/iso-string.js index 7bb022813..419f3638e 100644 --- a/node_modules/moment/src/lib/duration/iso-string.js +++ b/node_modules/moment/src/lib/duration/iso-string.js @@ -1,6 +1,10 @@ import absFloor from '../utils/abs-floor'; var abs = Math.abs; +function sign(x) { + return ((x > 0) - (x < 0)) || +x; +} + export function toISOString() { // for ISO strings we do not use the normal bubbling rules: // * milliseconds bubble up until they become hours @@ -35,7 +39,7 @@ export function toISOString() { var D = days; var h = hours; var m = minutes; - var s = seconds; + var s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : ''; var total = this.asSeconds(); if (!total) { @@ -44,13 +48,17 @@ export function toISOString() { return 'P0D'; } - return (total < 0 ? '-' : '') + - 'P' + - (Y ? Y + 'Y' : '') + - (M ? M + 'M' : '') + - (D ? D + 'D' : '') + + var totalSign = total < 0 ? '-' : ''; + var ymSign = sign(this._months) !== sign(total) ? '-' : ''; + var daysSign = sign(this._days) !== sign(total) ? '-' : ''; + var hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : ''; + + return totalSign + 'P' + + (Y ? ymSign + Y + 'Y' : '') + + (M ? ymSign + M + 'M' : '') + + (D ? daysSign + D + 'D' : '') + ((h || m || s) ? 'T' : '') + - (h ? h + 'H' : '') + - (m ? m + 'M' : '') + - (s ? s + 'S' : ''); + (h ? hmsSign + h + 'H' : '') + + (m ? hmsSign + m + 'M' : '') + + (s ? hmsSign + s + 'S' : ''); } diff --git a/node_modules/moment/src/lib/duration/prototype.js b/node_modules/moment/src/lib/duration/prototype.js index d923375cb..dd5470d38 100644 --- a/node_modules/moment/src/lib/duration/prototype.js +++ b/node_modules/moment/src/lib/duration/prototype.js @@ -6,6 +6,7 @@ import { abs } from './abs'; import { add, subtract } from './add-subtract'; import { as, asMilliseconds, asSeconds, asMinutes, asHours, asDays, asWeeks, asMonths, asYears, valueOf } from './as'; import { bubble } from './bubble'; +import { clone } from './clone'; import { get, milliseconds, seconds, minutes, hours, days, months, years, weeks } from './get'; import { humanize } from './humanize'; import { toISOString } from './iso-string'; @@ -27,6 +28,7 @@ proto.asMonths = asMonths; proto.asYears = asYears; proto.valueOf = valueOf; proto._bubble = bubble; +proto.clone = clone; proto.get = get; proto.milliseconds = milliseconds; proto.seconds = seconds; diff --git a/node_modules/moment/src/lib/duration/valid.js b/node_modules/moment/src/lib/duration/valid.js index 842585f32..033fd5b0f 100644 --- a/node_modules/moment/src/lib/duration/valid.js +++ b/node_modules/moment/src/lib/duration/valid.js @@ -1,4 +1,5 @@ import toInt from '../utils/to-int'; +import indexOf from '../utils/index-of'; import {Duration} from './constructor'; import {createDuration} from './create'; @@ -6,7 +7,7 @@ var ordering = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'se export default function isDurationValid(m) { for (var key in m) { - if (!(ordering.indexOf(key) !== -1 && (m[key] == null || !isNaN(m[key])))) { + if (!(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) { return false; } } diff --git a/node_modules/moment/src/lib/locale/locales.js b/node_modules/moment/src/lib/locale/locales.js index 99ee11571..4efebb8ff 100644 --- a/node_modules/moment/src/lib/locale/locales.js +++ b/node_modules/moment/src/lib/locale/locales.js @@ -52,11 +52,10 @@ function loadLocale(name) { module && module.exports) { try { oldLocale = globalLocale._abbr; - require('./locale/' + name); - // because defineLocale currently also sets the global locale, we - // want to undo that for lazy loaded locales + var aliasedRequire = require; + aliasedRequire('./locale/' + name); getSetGlobalLocale(oldLocale); - } catch (e) { } + } catch (e) {} } return locales[name]; } diff --git a/node_modules/moment/src/lib/moment/add-subtract.js b/node_modules/moment/src/lib/moment/add-subtract.js index b9e86a69d..e758b5d46 100644 --- a/node_modules/moment/src/lib/moment/add-subtract.js +++ b/node_modules/moment/src/lib/moment/add-subtract.js @@ -36,14 +36,14 @@ export function addSubtract (mom, duration, isAdding, updateOffset) { updateOffset = updateOffset == null ? true : updateOffset; - if (milliseconds) { - mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding); + if (months) { + setMonth(mom, get(mom, 'Month') + months * isAdding); } if (days) { set(mom, 'Date', get(mom, 'Date') + days * isAdding); } - if (months) { - setMonth(mom, get(mom, 'Month') + months * isAdding); + if (milliseconds) { + mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding); } if (updateOffset) { hooks.updateOffset(mom, days || months); diff --git a/node_modules/moment/src/lib/moment/diff.js b/node_modules/moment/src/lib/moment/diff.js index 9f4390818..85254dfc6 100644 --- a/node_modules/moment/src/lib/moment/diff.js +++ b/node_modules/moment/src/lib/moment/diff.js @@ -21,22 +21,18 @@ export function diff (input, units, asFloat) { units = normalizeUnits(units); - if (units === 'year' || units === 'month' || units === 'quarter') { - output = monthDiff(this, that); - if (units === 'quarter') { - output = output / 3; - } else if (units === 'year') { - output = output / 12; - } - } else { - delta = this - that; - output = units === 'second' ? delta / 1e3 : // 1000 - units === 'minute' ? delta / 6e4 : // 1000 * 60 - units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60 - units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst - units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst - delta; + switch (units) { + case 'year': output = monthDiff(this, that) / 12; break; + case 'month': output = monthDiff(this, that); break; + case 'quarter': output = monthDiff(this, that) / 3; break; + case 'second': output = (this - that) / 1e3; break; // 1000 + case 'minute': output = (this - that) / 6e4; break; // 1000 * 60 + case 'hour': output = (this - that) / 36e5; break; // 1000 * 60 * 60 + case 'day': output = (this - that - zoneDelta) / 864e5; break; // 1000 * 60 * 60 * 24, negate dst + case 'week': output = (this - that - zoneDelta) / 6048e5; break; // 1000 * 60 * 60 * 24 * 7, negate dst + default: output = this - that; } + return asFloat ? output : absFloor(output); } diff --git a/node_modules/moment/src/lib/moment/get-set.js b/node_modules/moment/src/lib/moment/get-set.js index 0d9fe5dfe..ce5ac823d 100644 --- a/node_modules/moment/src/lib/moment/get-set.js +++ b/node_modules/moment/src/lib/moment/get-set.js @@ -2,7 +2,8 @@ import { normalizeUnits, normalizeObjectUnits } from '../units/aliases'; import { getPrioritizedUnits } from '../units/priorities'; import { hooks } from '../utils/hooks'; import isFunction from '../utils/is-function'; - +import { daysInMonth } from '../units/month'; +import { isLeapYear } from '../units/year'; export function makeGetSet (unit, keepTime) { return function (value) { @@ -22,8 +23,13 @@ export function get (mom, unit) { } export function set (mom, unit, value) { - if (mom.isValid()) { - mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value); + if (mom.isValid() && !isNaN(value)) { + if (unit === 'FullYear' && isLeapYear(mom.year())) { + mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value, mom.month(), daysInMonth(value, mom.month())); + } + else { + mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value); + } } } diff --git a/node_modules/moment/src/lib/units/month.js b/node_modules/moment/src/lib/units/month.js index 28b4a1b98..f504ed35e 100644 --- a/node_modules/moment/src/lib/units/month.js +++ b/node_modules/moment/src/lib/units/month.js @@ -10,12 +10,19 @@ import { MONTH } from './constants'; import toInt from '../utils/to-int'; import isArray from '../utils/is-array'; import isNumber from '../utils/is-number'; +import mod from '../utils/mod'; import indexOf from '../utils/index-of'; import { createUTC } from '../create/utc'; import getParsingFlags from '../create/parsing-flags'; +import { isLeapYear } from '../units/year'; export function daysInMonth(year, month) { - return new Date(Date.UTC(year, month + 1, 0)).getUTCDate(); + if (isNaN(year) || isNaN(month)) { + return NaN; + } + var modMonth = mod(month, 12); + year += (month - modMonth) / 12; + return modMonth === 1 ? (isLeapYear(year) ? 29 : 28) : (31 - modMonth % 7 % 2); } // FORMATTING diff --git a/node_modules/moment/src/lib/units/year.js b/node_modules/moment/src/lib/units/year.js index a10e5b4be..8f3f94cda 100644 --- a/node_modules/moment/src/lib/units/year.js +++ b/node_modules/moment/src/lib/units/year.js @@ -56,7 +56,7 @@ export function daysInYear(year) { return isLeapYear(year) ? 366 : 365; } -function isLeapYear(year) { +export function isLeapYear(year) { return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; } diff --git a/node_modules/moment/src/lib/utils/is-object-empty.js b/node_modules/moment/src/lib/utils/is-object-empty.js index 1f2d939a5..695c3d248 100644 --- a/node_modules/moment/src/lib/utils/is-object-empty.js +++ b/node_modules/moment/src/lib/utils/is-object-empty.js @@ -1,8 +1,13 @@ export default function isObjectEmpty(obj) { - var k; - for (k in obj) { - // even if its not own property I'd still call it non-empty - return false; + if (Object.getOwnPropertyNames) { + return (Object.getOwnPropertyNames(obj).length === 0); + } else { + var k; + for (k in obj) { + if (obj.hasOwnProperty(k)) { + return false; + } + } + return true; } - return true; } diff --git a/node_modules/moment/src/lib/utils/mod.js b/node_modules/moment/src/lib/utils/mod.js new file mode 100644 index 000000000..8046cdac9 --- /dev/null +++ b/node_modules/moment/src/lib/utils/mod.js @@ -0,0 +1,3 @@ +export default function mod(n, x) { + return ((n % x) + x) % x; +} |