<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Displaying time spans with Arcade in dashboards in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/displaying-time-spans-with-arcade-in-dashboards/m-p/1128090#M5535</link>
    <description>&lt;P&gt;In your custom function, you're setting the numSeconds to an &lt;STRONG&gt;Abs&lt;/STRONG&gt; value, so when your &lt;STRONG&gt;DateDiff&lt;/STRONG&gt; returns a negative number, it's flipping it positive.&lt;/P&gt;&lt;P&gt;In the linked post, the authors do this so that the output is simply a duration, and is not concerned with the "direction" of the span. But the way &lt;STRONG&gt;DateDiff&lt;/STRONG&gt; functions, given &lt;STRONG&gt;DateDiff(date_a, date_b, units)&lt;/STRONG&gt;, if date_b is after date_a, you will get a &lt;EM&gt;negative&lt;/EM&gt; duration.&lt;/P&gt;&lt;P&gt;As far as why you're getting a negative duration between "now" and the last edit timestamp, that's a bit of a mystery. The implication is that somehow &lt;STRONG&gt;dateOpened&lt;/STRONG&gt; is coming in at a future date. You may need to check on the source of the data to see if it's configured properly for time zone, etc.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Dec 2021 17:53:09 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2021-12-21T17:53:09Z</dc:date>
    <item>
      <title>Displaying time spans with Arcade in dashboards</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/displaying-time-spans-with-arcade-in-dashboards/m-p/1045026#M4321</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I copied and slightly modified code from the following Blog:&amp;nbsp;&lt;A href="https://www.esri.com/arcgis-blog/products/ops-dashboard/real-time/displaying-time-spans-with-arcade-in-dashboards/" target="_blank"&gt;https://www.esri.com/arcgis-blog/products/ops-dashboard/real-time/displaying-time-spans-with-arcade-in-dashboards/&lt;/A&gt;&amp;nbsp;(Many thanks to &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119303"&gt;@David&lt;/a&gt; Nyenhuis and @Noora Golabi).&lt;/P&gt;&lt;P&gt;As my map gets updated, the seconds displayed start out in reverse like a countdown (54, 48, 42... to 0) and then proceed as expected (6, 12, 18...). The countdown shows up whether I specify type 1 or type 2.&lt;/P&gt;&lt;P&gt;Can anyone please tell me why I'm getting the countdown?&lt;/P&gt;&lt;P&gt;Here's what I'm using:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var dateOpened = $datapoint["last_edited_date"];&lt;BR /&gt;var currentTime = Now();&lt;BR /&gt;var secondsOpen = DateDiff(currentTime, dateOpened, 'seconds');&lt;/P&gt;&lt;P&gt;function formatElapsedTime(numSeconds, type) {&lt;BR /&gt;if (IsEmpty(type)) { type = 1 };&lt;BR /&gt;numSeconds = Floor(Abs(numSeconds));&lt;BR /&gt;var numMinutes = Floor(numSeconds/60,0);&lt;BR /&gt;var numHours = Floor(numSeconds/(60*60),0);&lt;BR /&gt;var numDays = Floor(numSeconds/(60*60*24),0);&lt;BR /&gt;&lt;BR /&gt;if (type == 1) {&lt;BR /&gt;var elapsedTime = When(&lt;BR /&gt;numMinutes &amp;lt; 1, 'This Map was Updated '+ numSeconds + ' Seconds Ago. Click Here to Zoom to Latest Update.',&lt;BR /&gt;numMinutes == 1, 'This Map was Updated 1 Minute Ago. Click Here to Zoom to Latest Update.',&lt;BR /&gt;numHours &amp;lt; 1, 'This Map was Updated '+ numMinutes + ' Minutes Ago. Click Here to Zoom to Latest Update.',&lt;BR /&gt;numHours == 1, 'This Map was Updated 1 Hour Ago. Click Here to Zoom to Latest Update.',&lt;BR /&gt;numDays &amp;lt; 1, 'This Map was Updated '+ numHours + ' Hours Ago. Click Here to Zoom to Latest Update.',&lt;BR /&gt;numDays == 1, 'This Map was Updated 1 Day Ago. Click Here to Zoom to Latest Update.',&lt;BR /&gt;'This Map was Updated '+ numDays +' Days Ago. Click Here to Zoom to Latest Update.',&lt;BR /&gt;);&lt;BR /&gt;return elapsedTime;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;if (type == 2) {&lt;BR /&gt;var relativeDate = DateAdd(Date(0,0,0,0,0,0), numSeconds, 'seconds');&lt;BR /&gt;var elapsedTime = When(&lt;BR /&gt;numHours &amp;lt; 1, Text(relativeDate,'mm:ss'),&lt;BR /&gt;numDays &amp;lt; 1, Text(relativeDate,'H:mm:ss'),&lt;BR /&gt;numDays + ' days ' + Text(relativeDate,'H:mm')&lt;BR /&gt;);&lt;BR /&gt;return elapsedTime;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var timeFormatted = formatElapsedTime(secondsOpen, 1);&lt;/P&gt;&lt;P&gt;return {&lt;BR /&gt;attributes: {&lt;BR /&gt;timeFormatted: timeFormatted&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 13:32:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/displaying-time-spans-with-arcade-in-dashboards/m-p/1045026#M4321</guid>
      <dc:creator>DEI</dc:creator>
      <dc:date>2021-04-08T13:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying time spans with Arcade in dashboards</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/displaying-time-spans-with-arcade-in-dashboards/m-p/1128090#M5535</link>
      <description>&lt;P&gt;In your custom function, you're setting the numSeconds to an &lt;STRONG&gt;Abs&lt;/STRONG&gt; value, so when your &lt;STRONG&gt;DateDiff&lt;/STRONG&gt; returns a negative number, it's flipping it positive.&lt;/P&gt;&lt;P&gt;In the linked post, the authors do this so that the output is simply a duration, and is not concerned with the "direction" of the span. But the way &lt;STRONG&gt;DateDiff&lt;/STRONG&gt; functions, given &lt;STRONG&gt;DateDiff(date_a, date_b, units)&lt;/STRONG&gt;, if date_b is after date_a, you will get a &lt;EM&gt;negative&lt;/EM&gt; duration.&lt;/P&gt;&lt;P&gt;As far as why you're getting a negative duration between "now" and the last edit timestamp, that's a bit of a mystery. The implication is that somehow &lt;STRONG&gt;dateOpened&lt;/STRONG&gt; is coming in at a future date. You may need to check on the source of the data to see if it's configured properly for time zone, etc.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 17:53:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/displaying-time-spans-with-arcade-in-dashboards/m-p/1128090#M5535</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-21T17:53:09Z</dc:date>
    </item>
  </channel>
</rss>

