UNPKG

locutus

Version:

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

18 lines (17 loc) 937 B
import { daysInMonth, normalizeCalendarMonth, normalizeCalendarYear, pythonWeekday } from "../_helpers/_calendar.js"; export 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 = normalizeCalendarYear(year, 'monthrange'); const normalizedMonth = normalizeCalendarMonth(month, 'monthrange'); return [pythonWeekday(normalizedYear, normalizedMonth, 1), daysInMonth(normalizedYear, normalizedMonth)]; }