/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{DateTime as t}from"luxon";function e(t){return Number.isNaN(t)||0===t?t:Math.trunc(t)}const i="esri.core.sql.SqlTimeStampOffset";class r{constructor(t){this._timeStampOffset=t,this.declaredRootClass=i,this._millis=null,this._date=null}static isTimestampOffset(t){return"object"==typeof t&&null!=t&&"declaredRootClass"in t&&t.declaredRootClass===i}toDateTime(){return this._date??=t.fromISO(this._timeStampOffset,{setZone:!0}),this._date}toMilliseconds(){return null!=this._millis?this._millis:(null!=this._date&&(this._millis??=this._date.toMillis()),this._millis??=Date.parse(this._timeStampOffset))}get isValid(){return this.toDateTime().isValid}get timezoneOffsetHour(){return e(this.toDateTime().offset/60)}get timezoneOffsetMinutes(){return e(this.toDateTime().offset%60)}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 r.fromDateTime(this.toDateTime().startOf("day"))}static fromJSDate(e){return new r(t.fromJSDate(e).toISO({includeOffset:!0}))}static fromDateTime(t){return new r(t.toISO({includeOffset:!0}))}static fromParts(t,e,i=0,s=0,a=0,o=0,n=0,m=!1,l=0,u=0){const f=`${t.toString().padStart(4,"0")}-${e.toString().padStart(2,"0")}-${i.toString().padStart(2,"0")}`;let S="";o<10&&(S="0");let d=`${s.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}:${S+o.toString()}`;0!==n&&(d+="."+n.toString().padStart(3,"0"));const h=`${m?"-":"+"}${l.toString().padStart(2,"0")}:${u.toString().padStart(2,"0")}`;return new r(f+"T"+d+h)}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 r.fromDateTime(e)}}export{r as SqlTimeStampOffset};
