UNPKG

@payfit/unity-components

Version:

25 lines (24 loc) 917 B
import { useMemo as e } from "react"; import { CalendarDate as t, createCalendar as n, getLocalTimeZone as r, today as i } from "@internationalized/date"; import { useLocale as a } from "react-aria-components/I18nProvider"; //#region src/components/date-calendar/hooks/useYearsList.ts function o({ yearsBefore: o = 100, yearsAfter: s = 30, startYear: c, endYear: l } = {}) { let { locale: u } = a(), d = i(r()), f = new Intl.DateTimeFormat().resolvedOptions().calendar, p = n(f), m = new t(p, d.year, d.month, d.day), h = c, g = l; return h === void 0 && (h = m.year - o), g === void 0 && (g = m.year + s), e(() => Array.from({ length: g - h + 1 }).map((e, n) => { let i = h + n, a = new t(p, i, 1, 1); return { id: i.toString(), name: a.toDate(r()).toLocaleString(u, { year: "numeric", calendar: p.identifier }) }; }), [ u, p, g, h ]); } //#endregion export { o as useYearsList };