| | 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) { |
| | |
| | var nowValue = new Date(hooks.now()); |
| | if (config._useUTC) { |
| | return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()]; |
| | } |
| | return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()]; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | export function configFromArray (config) { |
| | var i, date, input = [], currentDate, expectedWeekday, yearToUse; |
| |
|
| | if (config._d) { |
| | return; |
| | } |
| |
|
| | currentDate = currentDateArray(config); |
| |
|
| | |
| | if (config._w && config._a[DATE] == null && config._a[MONTH] == null) { |
| | dayOfYearFromWeekInfo(config); |
| | } |
| |
|
| | |
| | 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(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | for (i = 0; i < 3 && config._a[i] == null; ++i) { |
| | config._a[i] = input[i] = currentDate[i]; |
| | } |
| |
|
| | |
| | for (; i < 7; i++) { |
| | config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i]; |
| | } |
| |
|
| | |
| | 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); |
| | expectedWeekday = config._useUTC ? config._d.getUTCDay() : config._d.getDay(); |
| |
|
| | |
| | |
| | if (config._tzm != null) { |
| | config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm); |
| | } |
| |
|
| | if (config._nextDay) { |
| | config._a[HOUR] = 24; |
| | } |
| |
|
| | |
| | if (config._w && typeof config._w.d !== 'undefined' && config._w.d !== expectedWeekday) { |
| | getParsingFlags(config).weekdayMismatch = true; |
| | } |
| | } |
| |
|
| | 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; |
| |
|
| | |
| | |
| | |
| | |
| | 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); |
| |
|
| | |
| | week = defaults(w.w, curWeek.week); |
| |
|
| | if (w.d != null) { |
| | |
| | weekday = w.d; |
| | if (weekday < 0 || weekday > 6) { |
| | weekdayOverflow = true; |
| | } |
| | } else if (w.e != null) { |
| | |
| | weekday = w.e + dow; |
| | if (w.e < 0 || w.e > 6) { |
| | weekdayOverflow = true; |
| | } |
| | } else { |
| | |
| | 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; |
| | } |
| | } |
| |
|