I have a two fields that deal with the operating hours of cooling centers. The HOURS field has text that displays in a pop-up in AGOL. The HoursDays field converts the hours to the 24hr clock and those values are used in the Arcade expression to style the features in the webmap. The feature styles show either "Open now" or "Closed" based on the 24hr values.
// convert to 24 hour time
function ConvertTime(input) {
var theTime = input;
if (Find(":", theTime) > -1) {
var times = split(theTime, ":");
theTime = Number(times[0]) + Number(times[1]) / 60;
}
return Number(theTime);
}
var current = ConvertTime(Time(Now()));
var fTime = $feature.HoursDays;
var times = Split(fTime, ',')
var todaysTime = times[Weekday(Today()) - 1];
if (todaysTime == 'closed') return 'Closed'
var todaysTimes = Split(todaysTime, '-')
var start = ConvertTime(todaysTimes[0]);
var end = ConvertTime(todaysTimes[1]);
iif(current >= start && current <= end, 'Open now', 'Closed')
What I'm missing is a way to use Arcade to create a "Closed" style for government holidays, namely:
January 1st, 2025
January 20th, 2025
February 17th, 2025
May 26th, 2025
June 19th, 2025
July 4th, 2025
September 1st, 2025
October 13th, 2025
November 11th, 2025
November 27th, 2025
December 25th, 2025
Any ideas?
Solved! Go to Solution.
You could create an array of DateOnly holidays and test whether today as a DateOnly is in that array
var holidays = [
DateOnly(2025, 0, 1), //Months are 0-based
DateOnly(2025, 0, 20),
DateOnly(2025, 1, 17),
etc...
];
if (Includes(holidays, DateOnly())) {
return "Closed (Federal holiday)";
} else {
iif(current >= start && current <= end, "Open now", "Closed");
}
You could create an array of DateOnly holidays and test whether today as a DateOnly is in that array
var holidays = [
DateOnly(2025, 0, 1), //Months are 0-based
DateOnly(2025, 0, 20),
DateOnly(2025, 1, 17),
etc...
];
if (Includes(holidays, DateOnly())) {
return "Closed (Federal holiday)";
} else {
iif(current >= start && current <= end, "Open now", "Closed");
}