diff options
Diffstat (limited to 'node_modules/moment/src/lib/units')
-rw-r--r-- | node_modules/moment/src/lib/units/month.js | 9 | ||||
-rw-r--r-- | node_modules/moment/src/lib/units/year.js | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/node_modules/moment/src/lib/units/month.js b/node_modules/moment/src/lib/units/month.js index 28b4a1b98..f504ed35e 100644 --- a/node_modules/moment/src/lib/units/month.js +++ b/node_modules/moment/src/lib/units/month.js @@ -10,12 +10,19 @@ import { MONTH } from './constants'; 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); + year += (month - modMonth) / 12; + return modMonth === 1 ? (isLeapYear(year) ? 29 : 28) : (31 - modMonth % 7 % 2); } // FORMATTING diff --git a/node_modules/moment/src/lib/units/year.js b/node_modules/moment/src/lib/units/year.js index a10e5b4be..8f3f94cda 100644 --- a/node_modules/moment/src/lib/units/year.js +++ b/node_modules/moment/src/lib/units/year.js @@ -56,7 +56,7 @@ export function daysInYear(year) { return isLeapYear(year) ? 366 : 365; } -function isLeapYear(year) { +export function isLeapYear(year) { return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; } |