UNPKG

@brightsoftware/date-np

Version:

Simple & minimal Nepali date picker that just works.

123 lines (122 loc) 2.79 kB
import { NepaliDate as m } from "./NepaliDate.js"; import { CALENDAR as y } from "../data/locale.js"; import "react/jsx-runtime"; import "react"; import "clsx"; import "tailwind-merge"; import "./TimePicker/hooks/useTimePicker.js"; import "react-dom"; function S(t) { const r = t % 10, n = t % 100; return r === 1 && n !== 11 ? t + "st" : r === 2 && n !== 12 ? t + "nd" : r === 3 && n !== 13 ? t + "rd" : t + "th"; } function b(t) { const r = { January: "Jan", February: "Feb", // Note: fixing the typo in CALENDAR March: "Mar", April: "Apr", May: "May", June: "Jun", July: "Jul", August: "Aug", September: "Sep", October: "Oct", // Note: fixing the typo in CALENDAR November: "Nov", December: "Dec" }; return r[t] ? r[t] : { Baisakh: "Bais", Jestha: "Jest", Ashadh: "Aash", Shrawan: "Shra", Bhadra: "Bhad", Ashwin: "Ashw", Kartik: "Kart", Mangsir: "Mang", Poush: "Pous", Magh: "Magh", Falgun: "Falg", Chaitra: "Chai" }[t] || t.substring(0, 3); } function A(t) { return t instanceof m; } function g(t, r) { const n = A(t); let s, o, a, c; if (n) { const e = t; s = e.getFullYear(), o = e.getMonth(), a = e.getDate(), c = y.BS.months; } else { const e = t; s = e.getFullYear(), o = e.getMonth(), a = e.getDate(), c = y.AD.months; } const l = { yyyy: s.toString(), yy: s.toString().slice(-2), MMMM: c[o], MMM: b(c[o]), MM: (o + 1).toString().padStart(2, "0"), // Convert to 1-based and pad M: (o + 1).toString(), // Convert to 1-based dd: a.toString().padStart(2, "0"), d: a.toString(), do: S(a) }; let i = r; const p = Object.keys(l).sort((e, u) => u.length - e.length), h = {}; for (let e = 0; e < p.length; e++) { const u = p[e], M = `__PLACEHOLDER_${e}__`; h[M] = l[u]; const d = u.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), f = new RegExp(d, "g"); i = i.replace(f, M); } for (const e in h) i = i.replace(new RegExp(e, "g"), h[e]); return i; } function x(t) { return g(t, "yyyy-MM-dd"); } function B(t) { return g(t, "MMMM do, yyyy"); } function C(t) { return g(t, "MM/dd/yyyy"); } function E(t) { return g(t, "MMM dd, yyyy"); } function _(t) { if (!t || typeof t != "string") return; const [r, n] = t.split(":").map(Number); return { hours: r || 0, minutes: n || 0, seconds: 0 // Default seconds to 0 }; } const L = (t = 0) => { const r = /* @__PURE__ */ new Date(); return { hours: r.getHours() + t, minutes: r.getMinutes(), seconds: r.getSeconds() }; }; export { _ as convertToTimeValue, g as format, x as formatISO, B as formatLong, E as formatMedium, C as formatShort, L as getCurrentTime };