date-fns-jalali
Version:
Modern JavaScript date utility library for jalali calendar
38 lines (36 loc) • 1.3 kB
JavaScript
;
exports.getDaysInMonth = getDaysInMonth;
var _index = require("./toDate.js");
var _index2 = require("./constructFrom.js");
var _index3 = require("./_core/getMonth.js");
var _index4 = require("./_core/getDate.js");
var _index5 = require("./_core/getFullYear.js");
var _index6 = require("./_core/setFullYear.js");
/**
* @name getDaysInMonth
* @category Month Helpers
* @summary Get the number of days in a month of the given date.
*
* @description
* Get the number of days in a month of the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The given date
*
* @returns The number of days in a month
*
* @example
* // How many days are in February 2000?
* const result = getDaysInMonth(new Date(2000, 1))
* //=> 29
*/
function getDaysInMonth(date) {
const _date = (0, _index.toDate)(date);
const year = (0, _index5.getFullYear)(_date);
const monthIndex = (0, _index3.getMonth)(_date);
const lastDayOfMonth = (0, _index2.constructFrom)(date, 0);
(0, _index6.setFullYear)(lastDayOfMonth, year, monthIndex + 1, 0);
lastDayOfMonth.setHours(0, 0, 0, 0);
return (0, _index4.getDate)(lastDayOfMonth);
}