@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.19 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{SqlError as e,SqlErrorCodes as t}from"./errorSupport.js";function r(r){if(null!==r.precision||null!==r.secondary)throw new e(t.PrimarySecondaryQualifiers)}function s(e,t){if(t.includes(".")){const r=t.split(".");e.second=parseFloat(r[0]),e.millis=parseInt(r[1],10)}else e.second=parseFloat(t)}const l="esri.core.sql.SqlInterval";class a{constructor(){this.declaredRootClass=l,this.op="+",this.day=0,this.second=0,this.hour=0,this.month=0,this.year=0,this.minute=0,this.millis=0}static isInterval(e){return"object"==typeof e&&null!=e&&"declaredRootClass"in e&&e.declaredRootClass===l}static createFromMilliseconds(e){const t=new a;return t.second=e/1e3,t}static createFromValueAndQualifier(l,o,n){let i=null;const p=new a;if(p.op="-"===n?"-":"+","interval-period"===o.type){r(o);const a=new RegExp("^[0-9]{1,}$");if("year"===o.period||"month"===o.period)throw new e(t.YearMonthIntervals);if("second"===o.period){if(!/^[0-9]{1,}([.]{1}[0-9]{1,}){0,1}$/.test(l))throw new e(t.IllegalInterval);s(p,l)}else{if(!a.test(l))throw new e(t.IllegalInterval);p[o.period]=parseFloat(l)}}else{if(r(o.start),r(o.end),"year"===o.start.period||"month"===o.start.period||"year"===o.end.period||"month"===o.end.period)throw new e(t.YearMonthIntervals);switch(o.start.period){case"day":switch(o.end.period){case"hour":if(i=new RegExp("^[0-9]{1,} [0-9]{1,}$"),!i.test(l))throw new e(t.IllegalInterval);p[o.start.period]=parseFloat(l.split(" ")[0]),p[o.end.period]=parseFloat(l.split(" ")[1]);break;case"minute":if(i=new RegExp("^[0-9]{1,} [0-9]{1,2}:[0-9]{1,}$"),!i.test(l))throw new e(t.IllegalInterval);{p[o.start.period]=parseFloat(l.split(" ")[0]);const e=l.split(" ")[1].split(":");p.hour=parseFloat(e[0]),p.minute=parseFloat(e[1])}break;case"second":if(i=new RegExp("^[0-9]{1,} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,}([.]{1}[0-9]{1,}){0,1}$"),!i.test(l))throw new e(t.IllegalInterval);{p[o.start.period]=parseFloat(l.split(" ")[0]);const e=l.split(" ")[1].split(":");p.hour=parseFloat(e[0]),p.minute=parseFloat(e[1]),s(p,e[2])}break;default:throw new e(t.IllegalInterval)}break;case"hour":switch(o.end.period){case"minute":if(i=new RegExp("^[0-9]{1,}:[0-9]{1,}$"),!i.test(l))throw new e(t.IllegalInterval);p.hour=parseFloat(l.split(":")[0]),p.minute=parseFloat(l.split(":")[1]);break;case"second":if(i=new RegExp("^[0-9]{1,}:[0-9]{1,2}:[0-9]{1,}([.]{1}[0-9]{1,}){0,1}$"),!i.test(l))throw new e(t.IllegalInterval);{const e=l.split(":");p.hour=parseFloat(e[0]),p.minute=parseFloat(e[1]),s(p,e[2])}break;default:throw new e(t.IllegalInterval)}break;case"minute":if("second"!==o.end.period)throw new e(t.IllegalInterval);if(i=new RegExp("^[0-9]{1,}:[0-9]{1,}([.]{1}[0-9]{1,}){0,1}$"),!i.test(l))throw new e(t.IllegalInterval);{const e=l.split(":");p.minute=parseFloat(e[0]),s(p,e[1])}break;default:throw new e(t.IllegalInterval)}}return p}valueInMilliseconds(){return("-"===this.op?-1:1)*(this.millis+1e3*this.second+60*this.minute*1e3+60*this.hour*60*1e3+24*this.day*60*60*1e3+this.month*(365/12)*24*60*60*1e3+365*this.year*24*60*60*1e3)}}export{a as SqlInterval};