UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

21 lines (20 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.monthrange = monthrange; const _calendar_ts_1 = require("../_helpers/_calendar.js"); function monthrange(year, month) { // discuss at: https://locutus.io/python/calendar/monthrange/ // parity verified: Python 3.12 // original by: Kevin van Zonneveld (https://kvz.io) // example 1: monthrange(2024, 2) // returns 1: [3, 29] if (arguments.length === 0) { throw new TypeError("monthrange() missing 2 required positional arguments: 'year' and 'month'"); } if (arguments.length === 1) { throw new TypeError("monthrange() missing 1 required positional argument: 'month'"); } const normalizedYear = (0, _calendar_ts_1.normalizeCalendarYear)(year, 'monthrange'); const normalizedMonth = (0, _calendar_ts_1.normalizeCalendarMonth)(month, 'monthrange'); return [(0, _calendar_ts_1.pythonWeekday)(normalizedYear, normalizedMonth, 1), (0, _calendar_ts_1.daysInMonth)(normalizedYear, normalizedMonth)]; }