import toInt from '../utils/to-int';
import isArray from '../utils/is-array';
import isNumber from '../utils/is-number';
+import mod from '../utils/mod';
import indexOf from '../utils/index-of';
import { createUTC } from '../create/utc';
import getParsingFlags from '../create/parsing-flags';
+import { isLeapYear } from '../units/year';
export function daysInMonth(year, month) {
- return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
+ if (isNaN(year) || isNaN(month)) {
+ return NaN;
+ }
+ var modMonth = mod(month, 12);
+ if (modMonth === month) {
+ return month === 1 ? (isLeapYear(year) ? 29 : 28) : (31 - month % 7 % 2);
+ }
+ return daysInMonth(year + (month - modMonth) / 12, modMonth);
}
// FORMATTING
return isLeapYear(year) ? 366 : 365;
}
-function isLeapYear(year) {
+export function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
}