UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

6 lines 2.73 kB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.5.0-next.4 */ import{g as n}from"./p-8789682d.js";import{n as t,g as e}from"./p-743ed09c.js";function r(n,t,e){if(!n)return;const r=n.getTime(),a=!(t instanceof Date)||r>=t.getTime(),o=!(e instanceof Date)||r<=e.getTime();return a&&o}function a(n,t,e){if(!(n instanceof Date))return null;const r=n.getTime(),a=t instanceof Date&&r<t.getTime(),o=e instanceof Date&&r>e.getTime();return a?t:o?e:n}function o(n,t=!1){if(n instanceof Date)return n;if(!n||"string"!=typeof n)return null;const e=n.split(/[: T-]/).map(parseFloat),r=new Date(e[0],(e[1]||1)-1,e[2]||1);if(r.setFullYear(e[0]),isNaN(r.getTime()))throw new Error(`Invalid ISO 8601 date: "${n}"`);return t?y(r):r}function s(n,t){if(!t)return null;const{separator:e}=t,r=function(n,t){const{day:e,month:r,year:a}=f(n,t);return{day:parseInt(e),month:parseInt(r)-1,year:parseInt(a)}}(n,t),{day:a,month:o}=r,s=i(r.year,t),u=new Date(s,o,a);u.setFullYear(s);const c=a>0,d=o>-1,l=!isNaN(u.getTime()),D=n.split(e).filter((n=>n)).length>2,p=s.toString().length>0;return c&&d&&l&&D&&p?u:null}function i(n,t){return c(n,t,"read")}function u(n,t){return c(n,t,"write")}function c(n,t,e){return"buddhist"!==t["default-calendar"]?n:n+543*("read"===e?-1:1)}function f(n,e){const{separator:r,unitOrder:a}=e,o=m(a),s=n.split(r).map((n=>t.delocalize(n)));return{day:s[o.indexOf("d")],month:s[o.indexOf("m")],year:s[o.indexOf("y")]}}function d(n){return n instanceof Date?new Date(n.getTime()-6e4*n.getTimezoneOffset()).toISOString().split("T")[0]:""}function l(n,t){return n instanceof Date&&t instanceof Date&&n.getDate()===t.getDate()&&n.getMonth()===t.getMonth()&&n.getFullYear()===t.getFullYear()}function D(n){const t=n.getMonth(),e=new Date(n);return e.setMonth(t-1),t===e.getMonth()?new Date(n.getFullYear(),t,0):e}function p(n){const t=n.getMonth(),e=new Date(n);return e.setMonth(t+1),(t+2)%7==e.getMonth()%7?new Date(n.getFullYear(),t+2,0):e}function m(n){const t=n.toLowerCase();return["d","m","y"].sort(((n,e)=>t.indexOf(n)-t.indexOf(e)))}function w(n,t){return(n.getTime()-t.getTime())/864e5}function y(n){return n.setHours(23,59,59,999),n}const h={},g={};async function I(t){const r=e(t);if(h[r])return h[r];g[r]||(g[r]=fetch(n(`./assets/date-picker/nls/${r}.json`)).then((n=>n.json())).catch((()=>(console.error(`Translations for "${r}" not found or invalid, falling back to english`),I("en")))));const a=await g[r];return h[r]=a,a}function j(n){return n.map(((n,t)=>o(n,1===t)))}export{s as a,d as b,o as c,f as d,I as e,a as f,j as g,w as h,r as i,l as j,m as k,u as l,i as m,p as n,D as p,y as s}