@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.14 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import{JSONSupport as e}from"../core/JSONSupport.js";import{truncateDate as r,offsetDate as n}from"../core/timeUtils.js";import{property as i,subclass as s}from"../core/accessorSupport/decorators.js";import{system as l}from"./constants.js";import{reader as o}from"../core/accessorSupport/decorators/reader.js";import{writer as a}from"../core/accessorSupport/decorators/writer.js";var u;let m=class extends e{static{u=this}static get allTime(){return d}static get empty(){return p}static fromArray(t){return new u({start:null!=t[0]?new Date(t[0]):t[0],end:null!=t[1]?new Date(t[1]):t[1]})}constructor(t){super(t),this.end=null,this.start=null}readEnd(t,e){return null!=e.end?new Date(e.end):null}writeEnd(t,e){e.end=t?.getTime()??null}get isAllTime(){return this.equals(u.allTime)}get isEmpty(){return this.equals(u.empty)}readStart(t,e){return null!=e.start?new Date(e.start):null}writeStart(t,e){e.start=t?.getTime()??null}clone(){return new u({end:this.end,start:this.start})}equals(t){if(!t)return!1;const e=this.start?.getTime()??this.start,r=this.end?.getTime()??this.end,n=t.start?.getTime()??t.start,i=t.end?.getTime()??t.end;return e===n&&r===i}expandTo(t,e=l){if(this.isEmpty||this.isAllTime||"unknown"===t)return this.clone();let i=this.start;i&&(i=r(i,t,e));let s=this.end;if(s){const i=r(s,t,e);s=s.getTime()===i.getTime()?i:n(i,1,t,e)}return new u({start:i,end:s})}intersection(t){if(!t)return this.clone();if(this.isEmpty||t.isEmpty)return u.empty;if(this.isAllTime)return t.clone();if(t.isAllTime)return this.clone();const e=this.start?.getTime()??-1/0,r=this.end?.getTime()??1/0,n=t.start?.getTime()??-1/0,i=t.end?.getTime()??1/0;let s,l;return n>=e&&n<=r?s=n:e>=n&&e<=i&&(s=e),r>=n&&r<=i?l=r:i>=e&&i<=r&&(l=i),null==s||null==l||isNaN(s)||isNaN(l)?u.empty:new u({start:s===-1/0?null:new Date(s),end:l===1/0?null:new Date(l)})}offset(t,e,r=l){if(this.isEmpty||this.isAllTime||"unknown"===e)return this.clone();const i=new u,{start:s,end:o}=this;return null!=s&&(i.start=n(s,t,e,r)),null!=o&&(i.end=n(o,t,e,r)),i}toArray(){return this.isEmpty?[void 0,void 0]:[this.start?.getTime()??null,this.end?.getTime()??null]}union(t){if(!t||t.isEmpty)return this.clone();if(this.isEmpty)return t.clone();if(this.isAllTime||t.isAllTime)return d.clone();const e=null!=this.start&&null!=t.start?new Date(Math.min(this.start.getTime(),t.start.getTime())):null,r=null!=this.end&&null!=t.end?new Date(Math.max(this.end.getTime(),t.end.getTime())):null;return new u({start:e,end:r})}};t([i({type:Date,json:{write:{allowNull:!0}}})],m.prototype,"end",void 0),t([o("end")],m.prototype,"readEnd",null),t([a("end")],m.prototype,"writeEnd",null),t([i({readOnly:!0,json:{read:!1}})],m.prototype,"isAllTime",null),t([i({readOnly:!0,json:{read:!1}})],m.prototype,"isEmpty",null),t([i({type:Date,json:{write:{allowNull:!0}}})],m.prototype,"start",void 0),t([o("start")],m.prototype,"readStart",null),t([a("start")],m.prototype,"writeStart",null),m=u=t([s("esri.time.TimeExtent")],m);const d=new m,p=new m({start:void 0,end:void 0});export{m as default};