/pack-rat/003_pack_rat/pack-rat/node_modules/moment/src/lib/create/from-anything.js |
@@ -0,0 +1,110 @@ |
import isArray from '../utils/is-array'; |
import isObject from '../utils/is-object'; |
import isObjectEmpty from '../utils/is-object-empty'; |
import isUndefined from '../utils/is-undefined'; |
import isNumber from '../utils/is-number'; |
import isDate from '../utils/is-date'; |
import map from '../utils/map'; |
import { createInvalid } from './valid'; |
import { Moment, isMoment } from '../moment/constructor'; |
import { getLocale } from '../locale/locales'; |
import { hooks } from '../utils/hooks'; |
import checkOverflow from './check-overflow'; |
import { isValid } from './valid'; |
|
import { configFromStringAndArray } from './from-string-and-array'; |
import { configFromStringAndFormat } from './from-string-and-format'; |
import { configFromString } from './from-string'; |
import { configFromArray } from './from-array'; |
import { configFromObject } from './from-object'; |
|
function createFromConfig (config) { |
var res = new Moment(checkOverflow(prepareConfig(config))); |
if (res._nextDay) { |
// Adding is smart enough around DST |
res.add(1, 'd'); |
res._nextDay = undefined; |
} |
|
return res; |
} |
|
export function prepareConfig (config) { |
var input = config._i, |
format = config._f; |
|
config._locale = config._locale || getLocale(config._l); |
|
if (input === null || (format === undefined && input === '')) { |
return createInvalid({nullInput: true}); |
} |
|
if (typeof input === 'string') { |
config._i = input = config._locale.preparse(input); |
} |
|
if (isMoment(input)) { |
return new Moment(checkOverflow(input)); |
} else if (isDate(input)) { |
config._d = input; |
} else if (isArray(format)) { |
configFromStringAndArray(config); |
} else if (format) { |
configFromStringAndFormat(config); |
} else { |
configFromInput(config); |
} |
|
if (!isValid(config)) { |
config._d = null; |
} |
|
return config; |
} |
|
function configFromInput(config) { |
var input = config._i; |
if (isUndefined(input)) { |
config._d = new Date(hooks.now()); |
} else if (isDate(input)) { |
config._d = new Date(input.valueOf()); |
} else if (typeof input === 'string') { |
configFromString(config); |
} else if (isArray(input)) { |
config._a = map(input.slice(0), function (obj) { |
return parseInt(obj, 10); |
}); |
configFromArray(config); |
} else if (isObject(input)) { |
configFromObject(config); |
} else if (isNumber(input)) { |
// from milliseconds |
config._d = new Date(input); |
} else { |
hooks.createFromInputFallback(config); |
} |
} |
|
export function createLocalOrUTC (input, format, locale, strict, isUTC) { |
var c = {}; |
|
if (locale === true || locale === false) { |
strict = locale; |
locale = undefined; |
} |
|
if ((isObject(input) && isObjectEmpty(input)) || |
(isArray(input) && input.length === 0)) { |
input = undefined; |
} |
// object construction must be done this way. |
// https://github.com/moment/moment/issues/1423 |
c._isAMomentObject = true; |
c._useUTC = c._isUTC = isUTC; |
c._l = locale; |
c._i = input; |
c._f = format; |
c._strict = strict; |
|
return createFromConfig(c); |
} |
/pack-rat/003_pack_rat/pack-rat/node_modules/moment/src/lib/create/from-array.js |
@@ -0,0 +1,140 @@ |
import { hooks } from '../utils/hooks'; |
import { createDate, createUTCDate } from './date-from-array'; |
import { daysInYear } from '../units/year'; |
import { weekOfYear, weeksInYear, dayOfYearFromWeeks } from '../units/week-calendar-utils'; |
import { YEAR, MONTH, DATE, HOUR, MINUTE, SECOND, MILLISECOND } from '../units/constants'; |
import { createLocal } from './local'; |
import defaults from '../utils/defaults'; |
import getParsingFlags from './parsing-flags'; |
|
function currentDateArray(config) { |
// hooks is actually the exported moment object |
var nowValue = new Date(hooks.now()); |
if (config._useUTC) { |
return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()]; |
} |
return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()]; |
} |
|
// convert an array to a date. |
// the array should mirror the parameters below |
// 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; |
|
if (config._d) { |
return; |
} |
|
currentDate = currentDateArray(config); |
|
//compute day of the year from weeks and weekdays |
if (config._w && config._a[DATE] == null && config._a[MONTH] == null) { |
dayOfYearFromWeekInfo(config); |
} |
|
//if the day of the year is set, figure out what it is |
if (config._dayOfYear != null) { |
yearToUse = defaults(config._a[YEAR], currentDate[YEAR]); |
|
if (config._dayOfYear > daysInYear(yearToUse) || config._dayOfYear === 0) { |
getParsingFlags(config)._overflowDayOfYear = true; |
} |
|
date = createUTCDate(yearToUse, 0, config._dayOfYear); |
config._a[MONTH] = date.getUTCMonth(); |
config._a[DATE] = date.getUTCDate(); |
} |
|
// Default to current date. |
// * if no year, month, day of month are given, default to today |
// * if day of month is given, default month and year |
// * if month is given, default only year |
// * if year is given, don't default anything |
for (i = 0; i < 3 && config._a[i] == null; ++i) { |
config._a[i] = input[i] = currentDate[i]; |
} |
|
// Zero out whatever was not defaulted, including time |
for (; i < 7; i++) { |
config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i]; |
} |
|
// Check for 24:00:00.000 |
if (config._a[HOUR] === 24 && |
config._a[MINUTE] === 0 && |
config._a[SECOND] === 0 && |
config._a[MILLISECOND] === 0) { |
config._nextDay = true; |
config._a[HOUR] = 0; |
} |
|
config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input); |
// Apply timezone offset from input. The actual utcOffset can be changed |
// with parseZone. |
if (config._tzm != null) { |
config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm); |
} |
|
if (config._nextDay) { |
config._a[HOUR] = 24; |
} |
} |
|
function dayOfYearFromWeekInfo(config) { |
var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow; |
|
w = config._w; |
if (w.GG != null || w.W != null || w.E != null) { |
dow = 1; |
doy = 4; |
|
// TODO: We need to take the current isoWeekYear, but that depends on |
// how we interpret now (local, utc, fixed offset). So create |
// a now version of current config (take local/utc/offset flags, and |
// create now). |
weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(createLocal(), 1, 4).year); |
week = defaults(w.W, 1); |
weekday = defaults(w.E, 1); |
if (weekday < 1 || weekday > 7) { |
weekdayOverflow = true; |
} |
} else { |
dow = config._locale._week.dow; |
doy = config._locale._week.doy; |
|
var curWeek = weekOfYear(createLocal(), dow, doy); |
|
weekYear = defaults(w.gg, config._a[YEAR], curWeek.year); |
|
// Default to current week. |
week = defaults(w.w, curWeek.week); |
|
if (w.d != null) { |
// weekday -- low day numbers are considered next week |
weekday = w.d; |
if (weekday < 0 || weekday > 6) { |
weekdayOverflow = true; |
} |
} else if (w.e != null) { |
// local weekday -- counting starts from begining of week |
weekday = w.e + dow; |
if (w.e < 0 || w.e > 6) { |
weekdayOverflow = true; |
} |
} else { |
// default to begining of week |
weekday = dow; |
} |
} |
if (week < 1 || week > weeksInYear(weekYear, dow, doy)) { |
getParsingFlags(config)._overflowWeeks = true; |
} else if (weekdayOverflow != null) { |
getParsingFlags(config)._overflowWeekday = true; |
} else { |
temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy); |
config._a[YEAR] = temp.year; |
config._dayOfYear = temp.dayOfYear; |
} |
} |
/pack-rat/003_pack_rat/pack-rat/node_modules/moment/src/lib/create/from-string-and-format.js |
@@ -0,0 +1,113 @@ |
import { configFromISO, configFromRFC2822 } from './from-string'; |
import { configFromArray } from './from-array'; |
import { getParseRegexForToken } from '../parse/regex'; |
import { addTimeToArrayFromToken } from '../parse/token'; |
import { expandFormat, formatTokenFunctions, formattingTokens } from '../format/format'; |
import checkOverflow from './check-overflow'; |
import { HOUR } from '../units/constants'; |
import { hooks } from '../utils/hooks'; |
import getParsingFlags from './parsing-flags'; |
|
// constant that refers to the ISO standard |
hooks.ISO_8601 = function () {}; |
|
// constant that refers to the RFC 2822 form |
hooks.RFC_2822 = function () {}; |
|
// date from string and format string |
export function configFromStringAndFormat(config) { |
// TODO: Move this to another part of the creation flow to prevent circular deps |
if (config._f === hooks.ISO_8601) { |
configFromISO(config); |
return; |
} |
if (config._f === hooks.RFC_2822) { |
configFromRFC2822(config); |
return; |
} |
config._a = []; |
getParsingFlags(config).empty = true; |
|
// This array is used to make a Date, either with `new Date` or `Date.UTC` |
var string = '' + config._i, |
i, parsedInput, tokens, token, skipped, |
stringLength = string.length, |
totalParsedInputLength = 0; |
|
tokens = expandFormat(config._f, config._locale).match(formattingTokens) || []; |
|
for (i = 0; i < tokens.length; i++) { |
token = tokens[i]; |
parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0]; |
// console.log('token', token, 'parsedInput', parsedInput, |
// 'regex', getParseRegexForToken(token, config)); |
if (parsedInput) { |
skipped = string.substr(0, string.indexOf(parsedInput)); |
if (skipped.length > 0) { |
getParsingFlags(config).unusedInput.push(skipped); |
} |
string = string.slice(string.indexOf(parsedInput) + parsedInput.length); |
totalParsedInputLength += parsedInput.length; |
} |
// don't parse if it's not a known token |
if (formatTokenFunctions[token]) { |
if (parsedInput) { |
getParsingFlags(config).empty = false; |
} |
else { |
getParsingFlags(config).unusedTokens.push(token); |
} |
addTimeToArrayFromToken(token, parsedInput, config); |
} |
else if (config._strict && !parsedInput) { |
getParsingFlags(config).unusedTokens.push(token); |
} |
} |
|
// add remaining unparsed input length to the string |
getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength; |
if (string.length > 0) { |
getParsingFlags(config).unusedInput.push(string); |
} |
|
// clear _12h flag if hour is <= 12 |
if (config._a[HOUR] <= 12 && |
getParsingFlags(config).bigHour === true && |
config._a[HOUR] > 0) { |
getParsingFlags(config).bigHour = undefined; |
} |
|
getParsingFlags(config).parsedDateParts = config._a.slice(0); |
getParsingFlags(config).meridiem = config._meridiem; |
// handle meridiem |
config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem); |
|
configFromArray(config); |
checkOverflow(config); |
} |
|
|
function meridiemFixWrap (locale, hour, meridiem) { |
var isPm; |
|
if (meridiem == null) { |
// nothing to do |
return hour; |
} |
if (locale.meridiemHour != null) { |
return locale.meridiemHour(hour, meridiem); |
} else if (locale.isPM != null) { |
// Fallback |
isPm = locale.isPM(meridiem); |
if (isPm && hour < 12) { |
hour += 12; |
} |
if (!isPm && hour === 12) { |
hour = 0; |
} |
return hour; |
} else { |
// this is not supposed to happen |
return hour; |
} |
} |
/pack-rat/003_pack_rat/pack-rat/node_modules/moment/src/lib/create/from-string.js |
@@ -0,0 +1,202 @@ |
import { configFromStringAndFormat } from './from-string-and-format'; |
import { hooks } from '../utils/hooks'; |
import { deprecate } from '../utils/deprecate'; |
import getParsingFlags from './parsing-flags'; |
|
// 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) |
var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/; |
var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/; |
|
var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/; |
|
var isoDates = [ |
['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/], |
['YYYY-MM-DD', /\d{4}-\d\d-\d\d/], |
['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/], |
['GGGG-[W]WW', /\d{4}-W\d\d/, false], |
['YYYY-DDD', /\d{4}-\d{3}/], |
['YYYY-MM', /\d{4}-\d\d/, false], |
['YYYYYYMMDD', /[+-]\d{10}/], |
['YYYYMMDD', /\d{8}/], |
// YYYYMM is NOT allowed by the standard |
['GGGG[W]WWE', /\d{4}W\d{3}/], |
['GGGG[W]WW', /\d{4}W\d{2}/, false], |
['YYYYDDD', /\d{7}/] |
]; |
|
// iso time formats and regexes |
var isoTimes = [ |
['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/], |
['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/], |
['HH:mm:ss', /\d\d:\d\d:\d\d/], |
['HH:mm', /\d\d:\d\d/], |
['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/], |
['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/], |
['HHmmss', /\d\d\d\d\d\d/], |
['HHmm', /\d\d\d\d/], |
['HH', /\d\d/] |
]; |
|
var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i; |
|
// date from iso format |
export function configFromISO(config) { |
var i, l, |
string = config._i, |
match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string), |
allowTime, dateFormat, timeFormat, tzFormat; |
|
if (match) { |
getParsingFlags(config).iso = true; |
|
for (i = 0, l = isoDates.length; i < l; i++) { |
if (isoDates[i][1].exec(match[1])) { |
dateFormat = isoDates[i][0]; |
allowTime = isoDates[i][2] !== false; |
break; |
} |
} |
if (dateFormat == null) { |
config._isValid = false; |
return; |
} |
if (match[3]) { |
for (i = 0, l = isoTimes.length; i < l; i++) { |
if (isoTimes[i][1].exec(match[3])) { |
// match[2] should be 'T' or space |
timeFormat = (match[2] || ' ') + isoTimes[i][0]; |
break; |
} |
} |
if (timeFormat == null) { |
config._isValid = false; |
return; |
} |
} |
if (!allowTime && timeFormat != null) { |
config._isValid = false; |
return; |
} |
if (match[4]) { |
if (tzRegex.exec(match[4])) { |
tzFormat = 'Z'; |
} else { |
config._isValid = false; |
return; |
} |
} |
config._f = dateFormat + (timeFormat || '') + (tzFormat || ''); |
configFromStringAndFormat(config); |
} else { |
config._isValid = false; |
} |
} |
|
// 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}))$/; |
|
// 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); |
|
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' : ''); |
|
// 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()]; |
|
if (match[1].substr(0,3) !== momentDay) { |
getParsingFlags(config).weekdayMismatch = true; |
config._isValid = false; |
return; |
} |
} |
|
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']; |
} |
match[5] = timezone; |
config._i = match.splice(1).join(''); |
tzFormat = ' ZZ'; |
config._f = dayFormat + dateFormat + timeFormat + tzFormat; |
configFromStringAndFormat(config); |
getParsingFlags(config).rfc2822 = true; |
} else { |
config._isValid = false; |
} |
} |
|
// date from iso format or fallback |
export function configFromString(config) { |
var matched = aspNetJsonRegex.exec(config._i); |
|
if (matched !== null) { |
config._d = new Date(+matched[1]); |
return; |
} |
|
configFromISO(config); |
if (config._isValid === false) { |
delete config._isValid; |
} else { |
return; |
} |
|
configFromRFC2822(config); |
if (config._isValid === false) { |
delete config._isValid; |
} else { |
return; |
} |
|
// Final attempt, use Input Fallback |
hooks.createFromInputFallback(config); |
} |
|
hooks.createFromInputFallback = deprecate( |
'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' + |
'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' + |
'discouraged and will be removed in an upcoming major release. Please refer to ' + |
'http://momentjs.com/guides/#/warnings/js-date/ for more info.', |
function (config) { |
config._d = new Date(config._i + (config._useUTC ? ' UTC' : '')); |
} |
); |