text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.11/esri/copyright.txt for details.
  //>>built
  define("require exports ../../../../core/tsSupport/assignHelper ../../../../core/promiseUtils ./utils ../../statistics/summaryStatistics ../../support/utils ../../../support/utils".split(" "),function(z,g,t,n,h,u,k,v){function w(a){var b=Math.abs(a.avg),c=null;g.supportedAgeUnits.some(function(a){b>2*k.unitValueInDays[a]&&(c=a);return!!c});return c}function x(a){a=a.map(function(a){return'$feature["'+a+'"];'});return a.length?a.join("\n")+"\n":""}function p(a,b,c){a="number"===b?a:"date"===b?a.getTime():
  '$feature["'+a+'"]';return"var "+c+" \x3d "+a+";"}function q(a){var b=a.startTime,c=a.endTime,e=a.unit||"days",d=a.layer;a=k.getDateDiffSQL(d,b,c,e);var f=k.getDateType(d,b),d=k.getDateType(d,c),e=[p(b,f,"startTime"),p(c,d,"endTime"),'var retVal \x3d null;\n\n    if (startTime !\x3d null \x26\x26 endTime !\x3d null) {\n      startTime \x3d Date(startTime);\n      endTime \x3d Date(endTime);\n      retVal \x3d DateDiff(endTime, startTime, "'+e+'");\n    }\n\n    return retVal;'],l=[];"field"===f&&
  l.push(b);"field"===d&&l.push(c);return{valueExpression:x(l)+e.join("\n"),statisticsQuery:a,histogramQuery:a}}function m(a){var b=a.view,c=a.layer,e=a.unit;a=q({layer:c,startTime:a.startTime,endTime:a.endTime,unit:e});var d=a.valueExpression,b=t({layer:c,valueExpression:d},a.statisticsQuery,{view:b});return u(b).then(function(a){return{unit:e,statistics:a,valueExpression:d}})}Object.defineProperty(g,"__esModule",{value:!0});g.supportedAgeUnits="years months days hours minutes seconds".split(" ");
  var y=["hours","minutes","seconds"],r=["date","number"];g.verifyDates=function(a,b,c,e){var d=[],f=null;[b,c].every(function(b){(b=k.getDateType(a,b))&&d.push(b);return!!b})?d[0]===d[1]?"field"===d[0]?b===c&&(f=h.createError(e,"'startTime' and 'endTime' parameters cannot be identical")):f=h.createError(e,"invalid combination of 'startTime' and 'endTime' parameters"):-1<r.indexOf(d[0])&&-1<r.indexOf(d[1])&&(f=h.createError(e,"invalid combination of 'startTime' and 'endTime' parameters")):f=h.createError(e,
  "'startTime' and 'endTime' parameters must be one of these values: a date object, unix epoch time, name of a valid date field or \x3cnow\x3e");return f};g.formatDate=function(a,b,c){if("string"===typeof a){if((b=c.getField(a))&&"date"===b.type)return b.alias||b.name}else if("number"===typeof a||a instanceof Date)return b=-1<y.indexOf(b)?null:"date",v.formatDate(a,{selector:b});return a};g.getSuggestedAgeUnit=function(a){var b=a.view,c=a.layer,e=a.startTime,d=a.endTime;return m({view:b,layer:c,startTime:e,
  endTime:d,unit:"days"}).then(function(a){var g=a.statistics;a=a.valueExpression;if(null==g.avg)return n.reject(h.createError("getSuggestedAgeUnit","'avg' statistic is not available"));var f=w(g);return"days"===f?{unit:f,statistics:g,valueExpression:a}:m({view:b,layer:c,startTime:e,endTime:d,unit:f}).then(function(a){var b=a.statistics;a=a.valueExpression;return null==b.avg?n.reject(h.createError("getSuggestedAgeUnit","'avg' statistic is not available for suggested unit")):{unit:f,statistics:b,valueExpression:a}})})};
  g.getAgeExpressions=q;g.getAgeStatistics=m});