| | 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'; |
| |
|
| | |
| | hooks.ISO_8601 = function () {}; |
| |
|
| | |
| | hooks.RFC_2822 = function () {}; |
| |
|
| | |
| | export function configFromStringAndFormat(config) { |
| | |
| | if (config._f === hooks.ISO_8601) { |
| | configFromISO(config); |
| | return; |
| | } |
| | if (config._f === hooks.RFC_2822) { |
| | configFromRFC2822(config); |
| | return; |
| | } |
| | config._a = []; |
| | getParsingFlags(config).empty = true; |
| |
|
| | |
| | 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]; |
| | |
| | |
| | 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; |
| | } |
| | |
| | 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); |
| | } |
| | } |
| |
|
| | |
| | getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength; |
| | if (string.length > 0) { |
| | getParsingFlags(config).unusedInput.push(string); |
| | } |
| |
|
| | |
| | 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; |
| | |
| | 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) { |
| | |
| | return hour; |
| | } |
| | if (locale.meridiemHour != null) { |
| | return locale.meridiemHour(hour, meridiem); |
| | } else if (locale.isPM != null) { |
| | |
| | isPm = locale.isPM(meridiem); |
| | if (isPm && hour < 12) { |
| | hour += 12; |
| | } |
| | if (!isPm && hour === 12) { |
| | hour = 0; |
| | } |
| | return hour; |
| | } else { |
| | |
| | return hour; |
| | } |
| | } |
| |
|