UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.23 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{convertDateTimeFieldFormatToIntlOptions as t,convertDateFormatToIntlOptions as e,formatDate as n,formatTimestamp as o,formatTimeOnly as r,formatDateOnly as i}from"../../intl/date.js";import{isDateField as s,isDateOnlyField as a,isTimestampOffsetField as l}from"../../layers/support/fieldUtils.js";import{getWellKnownBasemapId as u}from"../../support/basemapUtils.js";import{loadArcade as f}from"../../support/loadArcade.js";import{utc as c}from"../../time/constants.js";import{getTimeZoneFormattingOptions as m}from"../../time/timeZoneUtils.js";const d=",",p={light:["streets","gray","topo","terrain","oceans","osm","gray-vector","streets-vector","topo-vector","streets-relief-vector","streets-navigation-vector","topo-3d","navigation-3d","streets-3d","osm-3d","gray-3d"],dark:["satellite","hybrid","dark-gray","dark-gray-vector","streets-night-vector","navigation-dark-3d","streets-dark-3d","dark-gray-3d"]},g="percent-of-total",y="field",h={exclude:["median"]},v={years:365,months:30,days:1,hours:1/24,minutes:1/1440,seconds:1/86400,milliseconds:1/864e5},T=new Set(["integer","small-integer"]);let w,Z=null;const $=["date","date-only","timestamp-offset"];function C(t){return s(t)||a(t)||l(t)}async function U(t,e){if(!t)return null;if(!w){const t=await import("../../core/sql/WhereClauseCache.js").then(t=>t.WhereClauseCache);w=new t(50,500)}return w.get(t,e)}async function F(t){const{field:e,field2:n,field3:o,normalizationField:r,valueExpression:i,fields:s}=t;let a=[];if(i){if(!Z){const{arcadeUtils:t}=await f();Z=t}a=Z.extractFieldNames(i)}return e&&a.push(e),n&&a.push(n),o&&a.push(o),r&&a.push(r),s&&a.push(...s),a}async function j(t,e){const n=[];for(const o of t)if(o){const t=await U(o,e),r=t?.fieldNames;r&&n.push(...r)}return[...new Set(n)]}function k(t){let e=t.normalizationType;return e||(t.normalizationField?e=y:null!=t.normalizationTotal&&(e=g)),e??void 0}function N(t){return String(t).padStart(2,"0")}function S(t,e,n){let o;if("date"===e||"number"===e){"number"===e&&(t=new Date(t));o=`TIMESTAMP'${n?t.getFullYear():t.getUTCFullYear()}-${N((n?t.getMonth():t.getUTCMonth())+1)}-${N(n?t.getDate():t.getUTCDate())} ${N(n?t.getHours():t.getUTCHours())}:${N(n?t.getMinutes():t.getUTCMinutes())}:${N(n?t.getSeconds():t.getUTCSeconds())}'`}else o=t;return o}function b(t,e,n,o){const{hasQueryEngine:r}=t,i=`(${S(n,D(t,n),r)} - ${S(e,D(t,e),r)})`;let s=v[o],a="/";s<1&&(s=1/s,a="*");return{sqlExpression:1===s?i:`(${i} ${a} ${s})`,sqlWhere:null}}function D(t,e){if(e instanceof Date)return"date";if("number"==typeof e)return"number";if("string"==typeof e){const n=t.getField(e);if("<now>"===e.toLowerCase())return;if(s(n))return"field"}}function M(t,e=p){for(const n in e)if(e[n].includes(t))return n}function x(t,e,n=!0){let o=null;return t&&("string"==typeof t?e.includes(t)&&(o=t):o=u(t)),n?o||"gray":o}function z(t,e){const n=e&&t.getField(e);return!!n&&T.has(n.type)}function E(t){return`cast(${t} as float)`}function q(s,a){const{format:l,fieldFormat:u,timeZoneOptions:f,fieldType:d}=a??{},p=u?t(u):null;let g,y;if(f&&({timeZone:g,timeZoneName:y}=m(f.layerTimeZone,f.datesInUnknownTimezone,f.viewTimeZone,p||e(l||"short-date-short-time"),d)),"string"==typeof s&&isNaN(Date.parse("time-only"===d?`1970-01-01T${s}Z`:s)))return s;switch(d){case"date-only":{const t=p||e(l||"short-date");return"string"==typeof s?i(s,{...t}):n(s,{...t,timeZone:c})}case"time-only":{const t=p||e(l||"short-time");return"string"==typeof s?r(s,t):n(s,{...t,timeZone:c})}case"timestamp-offset":{const t=l||p||f?p||e(l||"short-date-short-time"):void 0,r=t?{...t,timeZone:g,timeZoneName:y}:void 0;return"string"==typeof s?o(s,r):n(s,r)}default:{const t=l||p||f?p||e(l||"short-date-short-time"):void 0;return n("string"==typeof s?new Date(s):s,t?{...t,timeZone:g,timeZoneName:y}:void 0)}}}export{E as castIntegerFieldToFloat,$ as dateTypes,p as defaultBasemapGroups,h as defaultStatisticTypes,d as fieldDelimiter,q as formatAnyDate,M as getBasemapGroup,x as getBasemapId,b as getDateDiffSQL,D as getDateType,j as getFieldsFromWhereClauses,F as getFieldsList,k as getNormalizationType,U as getWhereClause,C as isAnyDateField,z as isIntegerField,v as unitValueInDays};