@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.78 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import e from"../../../core/Error.js";import{getDateType as t,getDateDiffSQL as n}from"../../support/utils.js";import{createLayerAdapter as r}from"../../support/adapters/support/layerUtils.js";const a=new Set(["date","number"]),i=["years","months","days","hours","minutes","seconds"];function s(n,r,i,s){const o=[];let m=null;return[r,i].every((e=>{const r=t(n,e);return r&&o.push(r),!!r}))?o[0]===o[1]?"field"===o[0]?r===i&&(m=new e(s,"'startTime' and 'endTime' parameters cannot be identical")):m=new e(s,"Invalid combination of 'startTime' and 'endTime' parameters"):a.has(o[0])&&a.has(o[1])&&(m=new e(s,"Invalid combination of 'startTime' and 'endTime' parameters")):m=new e(s,"'startTime' and 'endTime' parameters must be one of these values: a date object, unix epoch time, name of a valid date field or <now>"),m}function o(e){const t=e.map((e=>`$feature["${e}"];`));return t.length?t.join("\n")+"\n":""}function m(e,t,n){let r;return r="number"===t?e:"date"===t?e.getTime():'$feature["'+e+'"]',"var "+n+" = "+r+";"}function u(e,n,r,a){const i=t(e,n),s=t(e,r),u=[m(n,i,"startTime"),m(r,s,"endTime"),`var retVal = null;\n\n if (startTime != null && endTime != null) {\n startTime = Date(startTime);\n endTime = Date(endTime);\n retVal = DateDiff(endTime, startTime, "${a}");\n }\n\n return retVal;`],d=[];return"field"===i&&d.push(n),"field"===s&&d.push(r),o(d)+u.join("\n")}function d(e){const{layer:t,startTime:a,endTime:i}=e,s=r(t),o=e.unit||"days",m=n(s,a,i,o);return{valueExpression:u(s,a,i,o),statisticsQuery:m,histogramQuery:m}}export{d as getAgeExpressions,i as supportedAgeUnits,s as verifyDates};