UNPKG

@thi.ng/date

Version:

Datetime types, relative dates, math, iterators, composable formatters, locales

12 lines (11 loc) 524 B
import { implementsFunction } from "@thi.ng/checks/implements-function"; import { isNumber } from "@thi.ng/checks/is-number"; import { isString } from "@thi.ng/checks/is-string"; const ensureDate = (x) => isString(x) || isNumber(x) ? new Date(x) : implementsFunction(x, "toDate") ? x.toDate() : x; const ensureEpoch = (x) => (implementsFunction(x, "getTime") ? x : ensureDate(x)).getTime(); const isLeapYear = (year) => !(year % 4) && (!!(year % 100) || !(year % 400)); export { ensureDate, ensureEpoch, isLeapYear };