UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 3.65 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{DateOnly as n}from"./DateOnly.js";import{SqlError as e}from"./errorSupport.js";import{SqlInterval as t}from"./SqlInterval.js";import{SqlTimeStampOffset as r}from"./SqlTimestampOffset.js";import{TimeOnly as a}from"./TimeOnly.js";import{substituteUnknownTimezone as s,UnknownTimeZone as i}from"./UnknownTimeZone.js";import{DateTime as o,Zone as l}from"luxon";const p=/^(\d{1,2}):(\d{1,2}):(\d{1,2})$/,d=/^(\d{1,2}):(\d{1,2})$/,m=/^(\d{1,2}):(\d{1,2}):(\d{1,2}).([0-9]+)$/,I=/^(\d{4})-(\d{1,2})-(\d{1,2})$/,f=/^(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})(\.[0-9]+)?$/,u=/^(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})(\.[0-9]+)? {0,1}(\+|-)(\d{1,2}):(\d{1,2})$/,c=/^(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2})? {0,1}(\+|-)(\d{1,2}):(\d{1,2})$/,w=/^(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2})$/;function h(n,e){if(e instanceof l)return e===i.instance?o.fromMillis(n.getTime(),{zone:i.instance}):o.fromJSDate(n,{zone:e});switch(e){case"system":case"local":case null:return o.fromJSDate(n);default:return"unknown"===e?.toLowerCase()?o.fromMillis(n.getTime(),{zone:i.instance}):o.fromJSDate(n,{zone:e})}}function T(n){return t.isInterval(n)}function v(n){return o.isDateTime(n)}function y(e){return n.isDateOnly(e)}function S(n){return a.isTimeOnly(n)}function x(n){return r.isTimestampOffset(n)}function j(n){let t=p.exec(n);if(null!==t){const[,n,r,s]=t,i=a.fromParts(parseInt(n,10),parseInt(r,10),parseInt(s,10),0);if(null!==i)return i;throw new e("InvalidTime")}if(t=d.exec(n),null!==t){const[,n,r]=t,s=a.fromParts(parseInt(n,10),parseInt(r,10),0,0);if(null!==s)return s;throw new e("InvalidTime")}if(t=m.exec(n),null!==t){const[,n,r,s,i]=t,o=a.fromParts(parseInt(n,10),parseInt(r,10),parseInt(s,10),parseInt(i,10));if(null!==o)return o;throw new e("InvalidTime")}throw new e("InvalidTime")}function O(n,t){let a=f.exec(n);if(null!==a){const[,n,r,i,l,p,d,m]=a,I=o.fromObject({year:parseInt(n,10),month:parseInt(r,10),day:parseInt(i,10),hour:parseInt(l,10),minute:parseInt(p,10),second:parseInt(d,10),millisecond:m?parseInt(m.replace(".",""),10):0},{zone:s(t)});if(!1===I.isValid)throw new e("InvalidTimeStamp");return I}if(a=u.exec(n),null!==a){const[,n,t,s,i,o,l,p,d,m,I]=a,f=r.fromParts(parseInt(n,10),parseInt(t,10),parseInt(s,10),parseInt(i,10),parseInt(o,10),parseInt(l,10),p?parseInt(p.replace(".",""),10):0,"-"===d,parseInt(m,10),parseInt(I,10));if(!1===f.isValid)throw new e("InvalidTimeStamp");return f}if(a=c.exec(n),null!==a){const[,n,t,s,i,o,l,p,d]=a,m=r.fromParts(parseInt(n,10),parseInt(t,10),parseInt(s,10),parseInt(i,10),parseInt(o,10),0,0,"-"===l,parseInt(p,10),parseInt(d,10));if(!1===m.isValid)throw new e("InvalidTimeStamp");return m}if(a=w.exec(n),null!==a){const[,n,r,i,l,p]=a,d=o.fromObject({year:parseInt(n,10),month:parseInt(r,10),day:parseInt(i,10),hour:parseInt(l,10),minute:parseInt(p,10),second:0},{zone:s(t)});if(!1===d.isValid)throw new e("InvalidTimeStamp");return d}if(a=I.exec(n),null!==a){const[,n,r,i]=a,l=o.fromObject({year:parseInt(n,10),month:parseInt(r,10),day:parseInt(i,10),hour:0,minute:0,second:0},{zone:s(t)});if(!1===l.isValid)throw new e("InvalidTimeStamp");return l}throw new e("InvalidTimeStamp")}function D(t,r){const a=I.exec(t);if(null===a)try{return O(t,r)}catch{throw new e("InvalidDate")}const[,s,i,o]=a,l=n.fromParts(parseInt(s,10),parseInt(i,10),parseInt(o,10));if(null===l)throw new e("InvalidDate");return l}export{h as convertToExecutingTimeZone,y as isDateOnly,v as isDateTime,T as isSqlInterval,S as isTimeOnly,x as isTimestampOffset,D as parseDate,j as parseTime,O as parseTimestamp};