68fb25b ←d7343fdantonApr 11, 2026 api

trashed .bin-VsWjm9nR

? /sublimated/undefined
binary file or content unavailable
A /sublimated/undefined +57 -0
1import { daysInMonth } from '../units/month';
2import {
3 YEAR,
4 MONTH,
5 DATE,
6 HOUR,
7 MINUTE,
8 SECOND,
9 MILLISECOND,
10 WEEK,
11 WEEKDAY,
12} from '../units/constants';
13import getParsingFlags from '../create/parsing-flags';
14
15export default function checkOverflow(m) {
16 var overflow,
17 a = m._a;
18
19 if (a && getParsingFlags(m).overflow === -2) {
20 overflow =
21 a[MONTH] < 0 || a[MONTH] > 11
22 ? MONTH
23 : a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH])
24 ? DATE
25 : a[HOUR] < 0 ||
26 a[HOUR] > 24 ||
27 (a[HOUR] === 24 &&
28 (a[MINUTE] !== 0 ||
29 a[SECOND] !== 0 ||
30 a[MILLISECOND] !== 0))
31 ? HOUR
32 : a[MINUTE] < 0 || a[MINUTE] > 59
33 ? MINUTE
34 : a[SECOND] < 0 || a[SECOND] > 59
35 ? SECOND
36 : a[MILLISECOND] < 0 || a[MILLISECOND] > 999
37 ? MILLISECOND
38 : -1;
39
40 if (
41 getParsingFlags(m)._overflowDayOfYear &&
42 (overflow < YEAR || overflow > DATE)
43 ) {
44 overflow = DATE;
45 }
46 if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
47 overflow = WEEK;
48 }
49 if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
50 overflow = WEEKDAY;
51 }
52
53 getParsingFlags(m).overflow = overflow;
54 }
55
56 return m;
57}
A /sublimated/undefined +187 -0
1import { hooks } from '../utils/hooks';
2import { createDate, createUTCDate } from './date-from-array';
3import { daysInYear } from '../units/year';
4import {
5 weekOfYear,
6 weeksInYear,
7 dayOfYearFromWeeks,
8} from '../units/week-calendar-utils';
9import {
10 YEAR,
11 MONTH,
12 DATE,
13 HOUR,
14 MINUTE,
15 SECOND,
16 MILLISECOND,
17} from '../units/constants';
18import { createLocal } from './local';
19import defaults from '../utils/defaults';
20import getParsingFlags from './parsing-flags';
21
22function currentDateArray(config) {
23 // hooks is actually the exported moment object
24 var nowValue = new Date(hooks.now());
25 if (config._useUTC) {
26 return [
27 nowValue.getUTCFullYear(),
28 nowValue.getUTCMonth(),
29 nowValue.getUTCDate(),
30 ];
31 }
32 return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
33}
34
35// convert an array to a date.
36// the array should mirror the parameters below
37// note: all values past the year are optional and will default to the lowest possible value.
38// [year, month, day , hour, minute, second, millisecond]
39export function configFromArray(config) {
40 var i,
41 date,
42 input = [],
43 currentDate,
44 expectedWeekday,
45 yearToUse;
46
47 if (config._d) {
48 return;
49 }
50
51 currentDate = currentDateArray(config);
52
53 //compute day of the year from weeks and weekdays
54 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
55 dayOfYearFromWeekInfo(config);
56 }
57
58 //if the day of the year is set, figure out what it is
59 if (config._dayOfYear != null) {
60 yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
61
62 if (
63 config._dayOfYear > daysInYear(yearToUse) ||
64 config._dayOfYear === 0
65 ) {
66 getParsingFlags(config)._overflowDayOfYear = true;
67 }
68
69 date = createUTCDate(yearToUse, 0, config._dayOfYear);
70 config._a[MONTH] = date.getUTCMonth();
71 config._a[DATE] = date.getUTCDate();
72 }
73
74 // Default to current date.
75 // * if no year, month, day of month are given, default to today
76 // * if day of month is given, default month and year
77 // * if month is given, default only year
78 // * if year is given, don't default anything
79 for (i = 0; i < 3 && config._a[i] == null; ++i) {
80 config._a[i] = input[i] = currentDate[i];
81 }
82
83 // Zero out whatever was not defaulted, including time
84 for (; i < 7; i++) {
85 config._a[i] = input[i] =
86 config._a[i] == null ? (i === 2 ? 1 : 0) : config._a[i];
87 }
88
89 // Check for 24:00:00.000
90 if (
91 config._a[HOUR] === 24 &&
92 config._a[MINUTE] === 0 &&
93 config._a[SECOND] === 0 &&
94 config._a[MILLISECOND] === 0
95 ) {
96 config._nextDay = true;
97 config._a[HOUR] = 0;
98 }
99
100 config._d = (config._useUTC ? createUTCDate : createDate).apply(
101 null,
102 input
103 );
104 expectedWeekday = config._useUTC
105 ? config._d.getUTCDay()
106 : config._d.getDay();
107
108 // Apply timezone offset from input. The actual utcOffset can be changed
109 // with parseZone.
110 if (config._tzm != null) {
111 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
112 }
113
114 if (config._nextDay) {
115 config._a[HOUR] = 24;
116 }
117
118 // check for mismatching day of week
119 if (
120 config._w &&
121 typeof config._w.d !== 'undefined' &&
122 config._w.d !== expectedWeekday
123 ) {
124 getParsingFlags(config).weekdayMismatch = true;
125 }
126}
127
128function dayOfYearFromWeekInfo(config) {
129 var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek;
130
131 w = config._w;
132 if (w.GG != null || w.W != null || w.E != null) {
133 dow = 1;
134 doy = 4;
135
136 // TODO: We need to take the current isoWeekYear, but that depends on
137 // how we interpret now (local, utc, fixed offset). So create
138 // a now version of current config (take local/utc/offset flags, and
139 // create now).
140 weekYear = defaults(
141 w.GG,
142 config._a[YEAR],
143 weekOfYear(createLocal(), 1, 4).year
144 );
145 week = defaults(w.W, 1);
146 weekday = defaults(w.E, 1);
147 if (weekday < 1 || weekday > 7) {
148 weekdayOverflow = true;
149 }
150 } else {
151 dow = config._locale._week.dow;
152 doy = config._locale._week.doy;
153
154 curWeek = weekOfYear(createLocal(), dow, doy);
155
156 weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
157
158 // Default to current week.
159 week = defaults(w.w, curWeek.week);
160
161 if (w.d != null) {
162 // weekday -- low day numbers are considered next week
163 weekday = w.d;
164 if (weekday < 0 || weekday > 6) {
165 weekdayOverflow = true;
166 }
167 } else if (w.e != null) {
168 // local weekday -- counting starts from beginning of week
169 weekday = w.e + dow;
170 if (w.e < 0 || w.e > 6) {
171 weekdayOverflow = true;
172 }
173 } else {
174 // default to beginning of week
175 weekday = dow;
176 }
177 }
178 if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
179 getParsingFlags(config)._overflowWeeks = true;
180 } else if (weekdayOverflow != null) {
181 getParsingFlags(config)._overflowWeekday = true;
182 } else {
183 temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
184 config._a[YEAR] = temp.year;
185 config._dayOfYear = temp.dayOfYear;
186 }
187}
A /sublimated/undefined +20 -0
1import { normalizeObjectUnits } from '../units/aliases';
2import { configFromArray } from './from-array';
3import map from '../utils/map';
4
5export function configFromObject(config) {
6 if (config._d) {
7 return;
8 }
9
10 var i = normalizeObjectUnits(config._i),
11 dayOrDate = i.day === undefined ? i.date : i.day;
12 config._a = map(
13 [i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond],
14 function (obj) {
15 return obj && parseInt(obj, 10);
16 }
17 );
18
19 configFromArray(config);
20}