UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 2.08 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{DateTime as t}from"luxon";function e(t){return Number.isNaN(t)||0===t?t:Math.trunc(t)}const r="esri.core.sql.SqlTimeStampOffset";class i{constructor(t){this._timeStampOffset=t,this.declaredRootClass=r,this._date=null}static isTimestampOffset(t){return"object"==typeof t&&null!=t&&"declaredRootClass"in t&&t.declaredRootClass===r}toDateTime(){return this._date??=t.fromISO(this._timeStampOffset,{setZone:!0}),this._date}get isValid(){return this.toDateTime().isValid}get timezoneOffsetHour(){return e(this.toDateTime().offset/60)}get timezoneOffsetMinutes(){return e(this.toDateTime().offset%60)}toMilliseconds(){return this.toDateTime().toMillis()}get hour(){return this.toDateTime().hour}get minute(){return this.toDateTime().minute}get second(){return this.toDateTime().second}get day(){return this.toDateTime().day}get month(){return this.toDateTime().month}get year(){return this.toDateTime().year}startOfDay(){return i.fromDateTime(this.toDateTime().startOf("day"))}static fromJSDate(e){return new i(t.fromJSDate(e).toISO({includeOffset:!0}))}static fromDateTime(t){return new i(t.toISO({includeOffset:!0}))}static fromParts(t,e,r=0,o=0,a=0,s=0,n=0,m=!1,u=0,f=0){const S=`${t.toString().padStart(4,"0")}-${e.toString().padStart(2,"0")}-${r.toString().padStart(2,"0")}`;let d="";s<10&&(d="0");let l=`${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}:${d+s.toString()}`;0!==n&&(l+="."+n.toString().padStart(3,"0"));const c=`${m?"-":"+"}${u.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}`;return new i(S+"T"+l+c)}toStorageFormat(){return this._timeStampOffset}toString(){return this._timeStampOffset}toSQLValue(){let t=this.toDateTime().toSQL({includeOffset:!0,includeOffsetSpace:!0});return t&&(t=t.replace(".000","")),t}toSQLWithKeyword(){return`timestamp '${this.toSQLValue()}'`}addMilliseconds(t){const e=this.toDateTime().plus(t);return i.fromDateTime(e)}}export{i as SqlTimeStampOffset};