check-overflow.js (1622B)
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}