timeUtils.js 1.4 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import e from"../TimeExtent.js";import{unwrap as t,isSome as n,isNone as i}from"../core/maybe.js";import{eachAlways as o}from"../core/promiseUtils.js";import{offsetDate as r}from"../core/timeUtils.js";function m(e){return void 0!==e.timeInfo}async function s(n,r){if(0===n.length)return e.allTime;const s=n.filter(m);await Promise.all(s.map((e=>e.load({signal:r}))));const a=[],f=[];for(const e of s)"feature"!==e?.type&&"map-image"!==e?.type||!e.timeInfo.hasLiveData?f.push(e):a.push(e);const u=e=>i(e)||e.isAllTime,c=f.map((e=>e.timeInfo.fullTimeExtent));if(c.some(u))return e.allTime;const l=a.map((async e=>{const{timeExtent:n}=await e.fetchRecomputedExtents({signal:r});return n||t(e.timeInfo.fullTimeExtent)})),p=(await o(l)).map((e=>e.value));if(p.some(u))return e.allTime;return p.concat(c).reduce(((e,t)=>e.union(t)))}function a(t){if(!t)return t;const{start:i,end:o}=t;return new e({start:n(i)?r(i,-i.getTimezoneOffset(),"minutes"):i,end:n(o)?r(o,-o.getTimezoneOffset(),"minutes"):o})}function f(t){if(!t)return t;const{start:i,end:o}=t;return new e({start:n(i)?r(i,i.getTimezoneOffset(),"minutes"):i,end:n(o)?r(o,o.getTimezoneOffset(),"minutes"):o})}export{s as getTimeExtentFromLayers,f as toLocalTimeExtent,a as toUTCTimeExtent};