UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.09 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{SqlError as r,SqlErrorCodes as e}from"./errorSupport.js";import{isDateTime as t,isTimestampOffset as n,isDateOnly as i,isTimeOnly as o}from"./sqlDateParsingUtils.js";import{SqlTimeStampOffset as a}from"./SqlTimestampOffset.js";import{isUnknownTimeZone as s}from"./UnknownTimeZone.js";import{isNumber as u,isString as f}from"../../support/guards.js";import{DateTime as c}from"luxon";const l=321408e5,w=26784e5,m=864e5,p=36e5,d=6e4;function h(r){return!!t(r)||!!n(r)}function O(r){return!!t(r)||(!!i(r)||(!!n(r)||!!o(r)))}function v(o){if(t(o))return o.toMillis();if(i(o))return o.toNumber();if(n(o))return o.toMilliseconds();throw new r(e.InvalidDataType)}function I(l,w,m,p){if(null==l||null==w)return null;if(u(l)){if(u(w))return T(l,w,m);if(f(w))return D(l,w,m);if(O(w))throw new r(e.InvalidOperator);if(i(w))throw new r(e.InvalidOperator)}else if(f(l)){if(u(w))return M(l,w,m);if(f(w))return z(l,w,m);if(t(w))throw new r(e.InvalidOperator);if(i(w))throw new r(e.InvalidOperator);if(o(w))throw new r(e.InvalidOperator);if(n(w))throw new r(e.InvalidOperator)}else if(t(l)){if(h(w)){if(s(l.zone)){if(c.isDateTime(w)&&!s(w.zone))return j(l,w,m);if(a.isTimestampOffset(w))return j(l,w,m)}else if(c.isDateTime(w)&&s(w.zone)){if(!s(l.zone))return j(l,w,m);if(a.isTimestampOffset(l))return j(l,w,m)}return T(v(l),v(w),m)}if(f(w))throw new r(e.InvalidOperator);if(i(w))return N(l,w,m);if(o(w))throw new r(e.InvalidOperator);if(u(w))throw new r(e.InvalidOperator)}else if(i(l)){if(n(w))return b(l,w,m);if(t(w))return x(l,w,m);if(f(w))throw new r(e.InvalidOperator);if(i(w))return T(l.toNumber(),w.toNumber(),m);if(o(w))throw new r(e.InvalidOperator);if(u(w))throw new r(e.InvalidOperator)}else if(o(l)){if(o(w))return T(l.toNumber(),w.toNumber(),m);if(f(w))throw new r(e.InvalidOperator);if(u(w))throw new r(e.InvalidOperator);if(i(w))throw new r(e.InvalidOperator);if(h(w))throw new r(e.InvalidOperator)}else if(n(l)){if(h(w))return c.isDateTime(w)&&s(w.zone)?j(l,w,m):T(v(l),v(w),m);if(f(w))throw new r(e.InvalidOperator);if(i(w))return y(l,w,m);if(o(w))throw new r(e.InvalidOperator);if(u(w))throw new r(e.InvalidOperator)}switch(m){case"<>":return l!==w;case"=":return l===w;case">":return l>w;case"<":return l<w;case">=":return l>=w;case"<=":return l<=w}}function T(r,e,t){switch(t){case"<>":return r!==e;case"=":return r===e;case">":return r>e;case"<":return r<e;case">=":return r>=e;case"<=":return r<=e}}function D(r,e,t){const n=parseFloat(e);if(!isNaN(n))return T(r,n,t);const i=r.toString();switch(t){case"<>":return i!==e;case"=":return i===e;case">":return i>e;case"<":return i<e;case">=":return i>=e;case"<=":return i<=e}}function M(r,e,t){const n=parseFloat(r);if(!isNaN(n))return T(n,e,t);const i=e.toString();switch(t){case"<>":return r!==i;case"=":return r===i;case">":return r>i;case"<":return r<i;case">=":return r>=i;case"<=":return r<=i}}function z(r,e,t){switch(t){case"<>":return r!==e;case"=":return r===e;case">":return r>e;case"<":return r<e;case">=":return r>=e;case"<=":return r<=e}}function N(r,e,t){const n=e.toDateTimeLuxon(r.zone);return T((r=r.startOf("day")).toMillis(),n.toMillis(),t)}function y(r,e,t){const n=e.toDateTimeLuxon(r.toDateTime().zone);return T((r=r.startOfDay()).toMilliseconds(),n.toMillis(),t)}function x(r,e,t){const n=r.toDateTimeLuxon(e.zone);return e=e.startOf("day"),T(n.toMillis(),e.toMillis(),t)}function b(r,e,t){const n=r.toDateTimeLuxon(e.toDateTime().zone);return e=e.startOfDay(),T(n.toMillis(),e.toMilliseconds(),t)}function j(r,e,t){a.isTimestampOffset(r)&&(r=r.toDateTime()),a.isTimestampOffset(e)&&(e=e.toDateTime());const n=g(r),i=g(e);switch(t){case"<>":return n!==i;case"=":return n===i;case">":return n>i;case"<":return n<i;case">=":return n>=i;case"<=":return n<=i}}function g(r){return r.year*l+r.month*w+r.day*m+r.hour*p+r.minute*d+1e3*r.second+r.millisecond}export{v as dateValueInMilliseconds,O as isDateOrTimeValue,h as isDateTimeComparableValue,I as sqlCompare};