/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{resolveTimeZone as e}from"../intl/date.js";import{system as n}from"../time/constants.js";import{IANAZone as t,DateTime as s}from"luxon";const r={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5,months:26784e5,years:31536e6,decades:31536e7,centuries:31536e8,unknown:NaN};function o(r,o,i,c=n){if("unknown"===i)return r;const u=new t(e(c)),a=s.fromJSDate(r,{zone:u}),l="decades"===i||"centuries"===i?"year":T(i);return"decades"===i&&(o*=10),"centuries"===i&&(o*=100),a.plus({[l]:o}).toJSDate()}function i(e,n,t="milliseconds"){const s=e.getTime(),r=m(n,t,"milliseconds");return new Date(s+r)}function c(r,o,i=n){if("unknown"===o)return r;const c=new t(e(i)),u=s.fromJSDate(r,{zone:c});if("decades"===o||"centuries"===o){const e=u.startOf("year"),{year:n}=e,t=n-n%("decades"===o?10:100);return e.set({year:t}).toJSDate()}const a=T(o);return u.startOf(a).toJSDate()}function u(e,n,t="milliseconds"){const s=new Date(m(n,t,"milliseconds"));return s.setUTCFullYear(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()),s}function a(e,n="milliseconds"){const t=m(e.getUTCHours(),"hours","milliseconds"),s=m(e.getUTCMinutes(),"minutes","milliseconds"),r=m(e.getUTCSeconds(),"seconds","milliseconds");return m(t+s+r+e.getUTCMilliseconds(),"milliseconds",n)}function l(e,n){const t=new Date(e);return t.setUTCFullYear(n.getFullYear(),n.getMonth(),n.getDate()),t}function d(e){const n=new Date(0);return n.setHours(0),n.setMinutes(0),n.setSeconds(0),n.setMilliseconds(0),n.setFullYear(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()),n}function m(e,n,t){if(0===e)return 0;return e*r[n]/r[t]}function f(e){return e instanceof Date&&!isNaN(e.getTime())}function g(e,n){return e&&n?e.intersection(n):e||n}function T(e){switch(e){case"milliseconds":return"millisecond";case"seconds":return"second";case"minutes":return"minute";case"hours":return"hour";case"days":return"day";case"weeks":return"week";case"months":return"month";case"years":return"year"}}export{m as convertTime,f as isValidDate,u as makeUTCTime,g as mergeTimeExtents,r as millisecondsPerTimeUnit,o as offsetDate,i as offsetDateUTC,l as resetUTCDate,a as timeSinceUTCMidnight,c as truncateDate,d as truncateLocalTime};
