12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{p as e,k as n,f as t,C as r,h as u,D as s,b as o,E as a,F as c}from"../../chunks/languageUtils.js";import{getLocale as i}from"../../intl/locale.js";import{DateTime as l}from"luxon";function f(e){const n=new Date(e.getTime()),t=n.getFullYear(),r=new Date(0);r.setFullYear(t+1,0,4),r.setHours(0,0,0,0);const u=g(r),s=new Date(0);s.setFullYear(t,0,4),s.setHours(0,0,0,0);const o=g(s);return n.getTime()>=u.getTime()?t+1:n.getTime()>=o.getTime()?t:t-1}function g(e){const n=1,t=new Date(e.getTime()),r=t.getDay(),u=(r<n?7:0)+r-n;return t.setDate(t.getDate()-u),t.setHours(0,0,0,0),t}function d(e){const n=f(e),t=new Date(0);t.setFullYear(n,0,4),t.setHours(0,0,0,0);return g(t)}function m(e,n,t){return e+(h(t)?D:N)[n]}function h(e){return e%4==0&&(e%100!=0||e%400==0)}const N=[0,31,59,90,120,151,181,212,243,273,304,334],D=[0,31,60,91,121,152,182,213,244,274,305,335];function w(e){return null===e?e:isNaN(e.getTime())?null:e}function y(h,N){h.today=function(n,t){return N(n,t,(function(n,t,r){e(r,0,0);const u=new Date;return u.setHours(0,0,0,0),u}))},h.now=function(n,t){return N(n,t,(function(n,t,r){e(r,0,0);return new Date}))},h.timestamp=function(n,t){return N(n,t,(function(n,t,r){e(r,0,0);let u=new Date;return u=new Date(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate(),u.getUTCHours(),u.getUTCMinutes(),u.getUTCSeconds(),u.getUTCMilliseconds()),u}))},h.toutc=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?null:new Date(s.getUTCFullYear(),s.getUTCMonth(),s.getUTCDate(),s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds(),s.getUTCMilliseconds())}))},h.tolocal=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?null:l.utc(s.getFullYear(),s.getMonth()+1,s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds(),s.getMilliseconds()).toJSDate()}))},h.day=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getDate()}))},h.month=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getMonth()}))},h.year=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getFullYear()}))},h.hour=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getHours()}))},h.second=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getSeconds()}))},h.millisecond=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getMilliseconds()}))},h.minute=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getMinutes()}))},h.week=function(u,s){return N(u,s,(function(u,s,o){e(o,1,2);const a=n(o[0]);if(null===a)return NaN;const c=t(r(o[1],0));if(c<0||c>6)throw new Error("Invalid Parameter");const i=a.getDate(),l=a.getMonth(),f=a.getFullYear(),g=a.getDay(),d=m(i,l,f)-1,h=Math.floor(d/7);return g-c+(g-c<0?7:0)<d-7*h?h+1:h}))},h.weekday=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getDay()}))},h.isoweekday=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);if(null===s)return NaN;let o=s.getDay();return 0===o&&(o=7),o}))},h.isomonth=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:s.getMonth()+1}))},h.isoweek=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);if(null===s)return NaN;const o=g(s).getTime()-d(s).getTime();return Math.round(o/6048e5)+1}))},h.isoyear=function(t,r){return N(t,r,(function(t,r,u){e(u,1,1);const s=n(u[0]);return null===s?NaN:f(s)}))},h.date=function(r,a){return N(r,a,(function(r,a,c){if(e(c,0,7),3===c.length)return w(new Date(t(c[0]),t(c[1]),t(c[2]),0,0,0,0));if(4===c.length)return w(new Date(t(c[0]),t(c[1]),t(c[2]),t(c[3]),0,0,0));if(5===c.length)return w(new Date(t(c[0]),t(c[1]),t(c[2]),t(c[3]),t(c[4]),0,0));if(6===c.length)return w(new Date(t(c[0]),t(c[1]),t(c[2]),t(c[3]),t(c[4]),t(c[5]),0));if(7===c.length)return w(new Date(t(c[0]),t(c[1]),t(c[2]),t(c[3]),t(c[4]),t(c[5]),t(c[6])));if(2===c.length){let e,n=u(c[1]);return""===n?null:(n=s(n),e="X"===n?l.fromSeconds(t(c[0])):"x"===n?l.fromMillis(t(c[0])):l.fromFormat(u(c[0]),n,{locale:i(),numberingSystem:"latn"}),e.isValid?e.toJSDate():null)}if(1===c.length){if(o(c[0])){if(""===c[0].replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(c[0]))return n(c[0]+"-01-01")}const e=t(c[0]);if(!1===isNaN(e))return w(new Date(e));return n(c[0])}return 0===c.length?new Date:void 0}))},h.datediff=function(n,t){return N(n,t,(function(n,t,r){e(r,2,3);const s=a(r[0]),o=a(r[1]);if(null===s||null===o)return NaN;switch(u(r[2]).toLowerCase()){case"days":case"day":case"d":return s.diff(o,"days").days;case"months":case"month":return s.diff(o,"months").months;case"minutes":case"minute":case"m":return"M"===r[2]?s.diff(o,"months").months:s.diff(o,"minutes").minutes;case"seconds":case"second":case"s":return s.diff(o,"seconds").seconds;case"milliseconds":case"millisecond":case"ms":default:return s.diff(o).milliseconds;case"hours":case"hour":case"h":return s.diff(o,"hours").hours;case"years":case"year":case"y":return s.diff(o,"years").years}}))},h.dateadd=function(n,r){return N(n,r,(function(n,r,s){e(s,2,3);const o=a(s[0]);if(null===o)return null;let i=t(s[1]);if(isNaN(i))return o.toJSDate();let l="milliseconds";switch(u(s[2]).toLowerCase()){case"days":case"day":case"d":l="days",i=c(i);break;case"months":case"month":l="months",i=c(i);break;case"minutes":case"minute":case"m":l="M"===s[2]?"months":"minutes";break;case"seconds":case"second":case"s":l="seconds";break;case"milliseconds":case"millisecond":case"ms":l="milliseconds";break;case"hours":case"hour":case"h":l="hours";break;case"years":case"year":case"y":l="years"}return o.plus({[l]:i}).toJSDate()}))}}export{y as registerFunctions};
|