Currently our data displays in seconds, but I'd like to set it to display in minutes, hours, or days so that it's easier to read in the pop-up. How can I accomplish this with Arcade?
Hi jakecaldwell_ETISoftware ,
Have a look at the example below:
<SPAN class="keyword token">var</SPAN> seconds <SPAN class="operator token">=</SPAN> <SPAN class="number token">90061</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> days <SPAN class="operator token">=</SPAN> <SPAN class="token function">Floor</SPAN><SPAN class="punctuation token">(</SPAN>seconds <SPAN class="operator token">/</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="number token">60</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="number token">60</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="number token">24</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>days <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>result <SPAN class="operator token">=</SPAN> <SPAN class="token function">Round</SPAN><SPAN class="punctuation token">(</SPAN>days<SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" day(s) "</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> seconds <SPAN class="operator token">-</SPAN><SPAN class="operator token">=</SPAN> days <SPAN class="operator token">*</SPAN> <SPAN class="number token">60</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="number token">60</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="number token">24</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> hours <SPAN class="operator token">=</SPAN> <SPAN class="token function">Floor</SPAN><SPAN class="punctuation token">(</SPAN>seconds <SPAN class="operator token">/</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="number token">60</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="number token">60</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> seconds <SPAN class="operator token">-</SPAN><SPAN class="operator token">=</SPAN> hours <SPAN class="operator token">*</SPAN> <SPAN class="number token">60</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="number token">60</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> minutes <SPAN class="operator token">=</SPAN> <SPAN class="token function">Floor</SPAN><SPAN class="punctuation token">(</SPAN>seconds <SPAN class="operator token">/</SPAN> <SPAN class="number token">60</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> seconds <SPAN class="operator token">-</SPAN><SPAN class="operator token">=</SPAN> minutes <SPAN class="operator token">*</SPAN> <SPAN class="number token">60</SPAN><SPAN class="punctuation token">;</SPAN> result <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> <SPAN class="token function">Text</SPAN><SPAN class="punctuation token">(</SPAN>hours<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"00"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">":"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="token function">Text</SPAN><SPAN class="punctuation token">(</SPAN>minutes<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"00"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">":"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="token function">Text</SPAN><SPAN class="punctuation token">(</SPAN>seconds<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"00"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> result <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This returns:
1 day(s) 01:01:01<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Just assign the seconds field to the seconds variable on line 1.
This worked great! Thanks!
Hi jakecaldwell_ETISoftware , I'm glad it does. You can tweak the way you want to present the results. If you have any additional questions, just post them here and I will get back to you.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.