<?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: Arcade: Return a date in the future not including weekends and holidays in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1134079#M5728</link>
    <description>&lt;P&gt;The top half of your response &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt; worked well. Thank you!&lt;/P&gt;&lt;P&gt;I tried to implement the holiday portion but it isn't working. It's not failing or calling out any exceptions, but it doesn't seem to add any days. I noticed also that (2022, 1,1) is (year, month (0:Jan, 1:Feb, etc), day)), but it didn't help when I updated it. I keep having MLK day counted as a workday despite having put it as a holiday.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2022 21:28:12 GMT</pubDate>
    <dc:creator>Ser_Gio</dc:creator>
    <dc:date>2022-01-14T21:28:12Z</dc:date>
    <item>
      <title>Arcade: Return a date in the future not including weekends and holidays</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129567#M5586</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use the dateadd function in order to print out a work date in the future and it's working, but returning an incorrect date. Technically it is performing properly, but I am stumped at how to account for holidays and weekends so that I'm only dealing with working dates with Arcade.&amp;nbsp;&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;&lt;LI-CODE lang="java"&gt;var reference = 2.34;
//var difference = $datapoint["count_ObjectID"]-reference;
//var absoluteDifference = abs(difference);
var ratio = $datapoint["count_ObjectID"]/reference;
//var ratioChange = difference/reference;
//var percentage = ratio*100;
//var percentChange = ratioChange*100
var current = Today()
var Finish = text((DateAdd(current, ratio, 'days')), 'M/D/Y')
var ratioCeil = Ceil(ratio)

return {
    //textColor:'',
    //backgroundColor:'',
    topText: ratioceil + '* ',
    topTextColor: '#e60000',
    //topTextOutlineColor: '',
    topTextMaxSize: 'x-large',
    middleText: Finish,
    middleTextColor: '#e60000',
    middleTextOutlineColor: '',
    middleTextMaxSize: 'x-large',
    //bottomText: '',
    //bottomTextColor: '',
    //bottomTextOutlineColor: '',
    //bottomTextMaxSize: 'medium',
    //iconName:'',
    //iconAlign:'left',
    //iconColor:'',
    //iconOutlineColor:'',
    //noValue:false,
    //attributes: {
      // attribute1: '',
      // attribute2: ''
    // }
  }&lt;/LI-CODE&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;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lanatta_Sergio_0-1640811418613.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/30506iEE1BD0D4410AEAF3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Lanatta_Sergio_0-1640811418613.png" alt="Lanatta_Sergio_0-1640811418613.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The 2/23/2022 date should be 03/16/2022 if it took weekends and holidays into account as days not to be counted against the addition to the current date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the image below you can see the table I am referencing for some other widgets in the same dashboard to see that weekends and holidays are not included when I use this table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lanatta_Sergio_1-1640811749131.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/30507iC01C0A1C729863C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Lanatta_Sergio_1-1640811749131.png" alt="Lanatta_Sergio_1-1640811749131.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm not sure how I could exclude the few holidays and all weekends in the DateAdd function count.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 13:55:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129567#M5586</guid>
      <dc:creator>Ser_Gio</dc:creator>
      <dc:date>2021-12-30T13:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Return a date in the future not including weekends and holidays</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129574#M5587</link>
      <description>&lt;P&gt;That is perplexing. I think the weekend could be solved by checking the &lt;A href="https://developers.arcgis.com/arcade/function-reference/date_functions/#isoweekday" target="_blank" rel="noopener"&gt;weekday&lt;/A&gt; of the forecasted date and if weekday is 6 or 7, add 1 or 2 days respectively.&lt;/P&gt;&lt;P&gt;About the holiday question, that's a bit harder to tackle. There are a variety of Holiday calendars. &lt;A href="https://community.esri.com/t5/arcgis-online-questions/configuring-the-next-pickup-arcade-expression-in/td-p/1069662" target="_blank" rel="noopener"&gt;This post&lt;/A&gt; has a known list and then checks against that list to add days if needed. You could create a hosted layer that contains all of the holidays for your locality and add the dates for a year at a time before the first day of the year and then use it in a &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#featureset" target="_blank" rel="noopener"&gt;FeatureSet&lt;/A&gt; to check for Holidays.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 21:35:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129574#M5587</guid>
      <dc:creator>DougGreen</dc:creator>
      <dc:date>2021-12-29T21:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Return a date in the future not including weekends and holidays</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129648#M5592</link>
      <description>&lt;P&gt;Like &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/70326"&gt;@DougGreen&lt;/a&gt;&amp;nbsp; said, holidays can be trickier, but I think we can come up with a decent expression for the weekends. Based on your code, it looks like the &lt;STRONG&gt;ratio&lt;/STRONG&gt; variable is equivalent to the "number of workdays", and we're taking the ceiling of partial days.&lt;/P&gt;&lt;P&gt;In short:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Figure out how many work weeks are represented by the "days" count.&lt;/LI&gt;&lt;LI&gt;Figure out how many weekends fall in that span.&lt;/LI&gt;&lt;LI&gt;Adjust the output accordingly.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var reference = 2.34

var daysToFinish = $datapoint["count_ObjectID"]/reference;

var current = Today()

// Calculate number of "work weeks" (5 days) covered by number
var workWeeks = Floor(daysToFinish/5)

// Calculate number of reamining days after the work weeks have elapsed
var remainderDays = Ceil(daysToFinish % 5)

// Get current weekday number
var currentWorkDay = Weekday(current)

// If current weekday plus remainder days crosses a weekend, add two more days
if (currentWorkDay + remainderDays &amp;gt; 5) {
    remainderDays += 2
}

var endDate = DateAdd(current, (workWeeks * 7) + remainderDays, 'days')

return endDate&lt;/LI-CODE&gt;&lt;P&gt;As a proof of concept, I hard-coded 56 into the expression to test it.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1640878171887.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/30520i541F973C51FA0FA6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1640878171887.png" alt="jcarlson_0-1640878171887.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So, there's your weekends!&lt;/P&gt;&lt;P&gt;Holidays, though, I think there's no way to do it without a list of holidays to check against. But supposing you did have such a list, it would look like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var holidays = [
    Date(2022, 1, 1), // New Year's Day
    Date(2022, 1, 17), // MLK Day
    ... //etc
]

// Check if each holiday falls within the start and end dates and increment the remainder days as needed
for (var h in holidays){
    if (h &amp;gt;= current &amp;amp;&amp;amp; h &amp;lt;=  endDate){
        remainderDays += 1
    }
}&lt;/LI-CODE&gt;&lt;P&gt;The trouble with this, though, is if there are added holidays, the &lt;STRONG&gt;endDate&lt;/STRONG&gt; changes, and you'll need to re-check if it lands in a weekend and move the date accordingly.&lt;/P&gt;&lt;P&gt;I think you might need to wrap some of this into a custom function to make it easier to re-calculate as the end date moves.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:36:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129648#M5592</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-30T15:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Return a date in the future not including weekends and holidays</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129649#M5593</link>
      <description>&lt;P&gt;Thank you guys! Testing it now and will let you know!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:38:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129649#M5593</guid>
      <dc:creator>Ser_Gio</dc:creator>
      <dc:date>2021-12-30T15:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Return a date in the future not including weekends and holidays</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1134079#M5728</link>
      <description>&lt;P&gt;The top half of your response &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt; worked well. Thank you!&lt;/P&gt;&lt;P&gt;I tried to implement the holiday portion but it isn't working. It's not failing or calling out any exceptions, but it doesn't seem to add any days. I noticed also that (2022, 1,1) is (year, month (0:Jan, 1:Feb, etc), day)), but it didn't help when I updated it. I keep having MLK day counted as a workday despite having put it as a holiday.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 21:28:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1134079#M5728</guid>
      <dc:creator>Ser_Gio</dc:creator>
      <dc:date>2022-01-14T21:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Return a date in the future not including weekends and holidays</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1134177#M5732</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;So I have two solutions that a friend and I (mostly him) were able to come up with, but while testing it we realized that while the test environment seemed to be executed properly, the dashboard indicator said "Unable to execute Arcade script". We performed some process of elimination and discovered that our custom functions seemed to be working in the test environment, but failing in the display widget for the dashboard. Below is the code that failed. After that snippet is the final code rewritten to not use functions (and it displayed properly). The two codes main purpose is to get that date in the future accounting for weekends and holidays, but the second code is modified to show other relevant data.&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Does anyone know why the first code, which is cleaner and passed the environment test failed to display in the widget?&lt;/STRONG&gt;&lt;/FONT&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var reference = 2.34
var daystofinish = $datapoint["count_ObjectID"]/reference;
function addworkdays (startdate , num_of_working_days) {
    var date = startdate;
    for (var i=0; i &amp;lt; num_of_working_days; i++) {
    date = dateadd(date,1,'days');
    date = avoidweekends(date);
    }
    return date;
}
function avoidweekends (funcdate) {
    var holidays = 
[   Date(2022, 1, 2), // New Year's Day
    Date(2022, 12, 31), // New Year's Day
    Date(2022, 0, 17), // MLK Day
    Date(2022, 0, 18), // Susan B Anthony Day
    Date(2022, 0, 19), // Memorial Day
    Date(2022, 5, 20), // Juneteeth Day
    Date(2022, 7, 4), // Independence Day
    Date(2022, 9, 5), // Labor Day
    Date(2022, 10, 10), // Columbus Day
    Date(2022, 11, 11), // Veteran's Day
    Date(2022, 11, 24),  // Thanksgiving Day
    Date(2022, 12, 26), // Christmas Day
]
    var sunday = 0;
    var saturday = 6;
    if (weekday(funcdate) == sunday || weekday(funcdate) ==saturday || Includes(holidays, funcdate)) {
    funcdate = dateadd(funcdate, 1,'days');
    return avoidweekends(funcdate);
    }else{
        return funcdate;
    }
}

var outdate = addworkdays(today(), (daystofinish));

return {
middleText: outdate
}

//this code passed the test environment but failed in the widget as mentioned above. &lt;/LI-CODE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once the functions were eliminated,&amp;nbsp; accounting for predictable holidays was done with some messier coding, but it appears to be working properly. See below for the solution that worked in the widget.&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var holidays = 
[   Date(2021, 11, 31), // New Year's Day
    Date(2022, 0, 17), // MLK Day
    Date(2022, 1, 21), // presday
    Date(2022, 4, 30), // Memorial Day
    Date(2022, 5, 20), // Juneteeth Day
    Date(2022, 6, 4), // Independence Day
    Date(2022, 8, 5), // Labor Day
    Date(2022, 9, 10), // Columbus Day
    Date(2022, 10, 11), // Veteran's Day
    Date(2022, 10, 24),  // Thanksgiving Day
    Date(2022, 10, 25),  // day after Thanksgiving Day
    Date(2022, 11, 26), // Christmas Day
]

var sunday = 0;
var saturday = 6;
var currentday = today();
var sitesleft = $datapoint["count_ObjectID"]
var rate = 2.34
var days_to_add = ceil(sitesleft/rate);
var calculated_date = currentday;
for (var i=0; i &amp;lt; days_to_add; i++) {
    calculated_date = dateadd(calculated_date,1,'days');
    if (weekday(calculated_date) == saturday){ 
        calculated_date = dateadd(calculated_date, 2,'days')
    }
    if (weekday(calculated_date) == sunday){ 
        calculated_date = dateadd(calculated_date, 1,'days');
    }
    // at this point the calcdate should 
    //be a weekday but could still be a holiday
    if (Includes(holidays, calculated_date)){ 
        // checks if this new date is a holiday
        if (weekday(calculated_date) == 4){ 
            //checks if its a thursday holiday
            if (Includes(holidays,dateadd(calculated_date,1,'days'))){
                // followed by a fri holiday aka thanksgiving
            calculated_date = dateadd(calculated_date, 4,'days');
            //adds 4 days to thursday to get to monday
            }else{
                /* if its not thanksgiving then Fri is not a holiday, 
                so add 1 day to get to Fri*/
                calculated_date = dateadd(calculated_date, 1,'days');
            } 
        }
        if (weekday(calculated_date) &amp;gt; 0 &amp;amp;&amp;amp; 
            weekday(calculated_date) &amp;lt; 4){
            // if the holiday lands on a mon,tues,weds
            calculated_date = dateadd(calculated_date, 1,'days');
        }
        if (weekday(calculated_date) == 5){
            // if the holiday lands on a Fri
            calculated_date = dateadd(calculated_date, 3,'days');
        }
    }
}
return {
    topText: sitesleft+ ' inspections reports remaining* ',
    topTextMaxSize: 'medium',
    middleText: days_to_add+ '** inspection days remaining',
    middleTextMaxSize: 'medium',
    bottomText: text((calculated_date), 'M/D/Y')+ ' end date',
    bottomTextMaxSize: 'Large',
    bottomTextColor: IIf(calculated_date &amp;gt;= Date(2022,03,28), 'red', 
    'green')
    
}&lt;/LI-CODE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jan 2022 08:41:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1134177#M5732</guid>
      <dc:creator>Ser_Gio</dc:creator>
      <dc:date>2022-01-15T08:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Return a date in the future not including weekends and holidays</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1134194#M5733</link>
      <description>&lt;P&gt;My reply was labeled as spam by accident i think. I believe a friend and I found two solutions, one which won't post to the indicator dashboard and one which does. The only main difference we can note being the use of functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;Why would the code below return as ok in the test environment but unable in the dashboard?&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function addworkdays (startdate , num_of_working_days) {
    var date = startdate;
    for (var i=0; i &amp;lt; num_of_working_days; i++) {
    date = dateadd(date,1,'days');
    date = avoidweekends(date);
    }
    return date;
}
function avoidweekends (funcdate) {
    var holidays = 
[   Date(2022, 1, 2), // New Year's Day
    Date(2022, 12, 31), // New Year's Day
    Date(2022, 0, 17), // MLK Day
    Date(2022, 0, 18), // Susan B Anthony Day
    Date(2022, 0, 19), // Memorial Day
    Date(2022, 5, 20), // Juneteeth Day
    Date(2022, 7, 4), // Independence Day
    Date(2022, 9, 5), // Labor Day
    Date(2022, 10, 10), // Columbus Day
    Date(2022, 11, 11), // Veteran's Day
    Date(2022, 11, 24),  // Thanksgiving Day
    Date(2022, 12, 26), // Christmas Day
]
    var sunday = 0;
    var saturday = 6;
    if (weekday(funcdate) == sunday ||
        weekday(funcdate) ==saturday ||
        Includes(holidays, funcdate)) {
    funcdate = dateadd(funcdate, 1,'days');
    return avoidweekends(funcdate);
    }else{
        return funcdate;
    }
}
var outdate = addworkdays(today(), 1);
return {
  middleText: outdate
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jan 2022 14:33:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1134194#M5733</guid>
      <dc:creator>Ser_Gio</dc:creator>
      <dc:date>2022-01-15T14:33:25Z</dc:date>
    </item>
  </channel>
</rss>

