Only show Features on map that are between Start and End Date/Time Fields

223
2
02-26-2024 11:54 AM
Labels (3)
JustinNettleton1
New Contributor III

I have web service that is showing road closures that usually last less than a day. I am trying to find a way to only show the closures on the map that are active, so after the start date/time and before the end date/time.  I have been trying to accomplish this by  using an arcade symbology expression, but I can't figure out. Says the expression is right but doesn't show the closures I want on the map. 

Is this the best way to accomplish this?  Does anybody have an idea on how to best set up the expression?   I have 3 types of date time fields to choose from, I can't figure out any of them out.   I have attached an image of the field options I have. 

Here is one expression I tried with the epoch date fields. 

//ToLocal(Timestamp())

var started = $feature.closureStartEpoch
    var closed = $feature.closureEndEpoch
var present = date()

// if current date/time is greater than or equal to the start time
// AND current date/time is less than or equal to the close time
// return open, otherwise its closed
If (present >= started && present <= closed) {
    return "Open"
If (present <= started && present >= closed) {
    return "Closed"
}
} else {
    return "Other"
}
 
These are the Start and End Date/Time fields I have to choose from. 
TimeOptions.jpg
Tags (2)
0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

You can't directly compare the epoch number to a Date like that. You'll have to convert it to a Date. Arcade can create a Date from an epoch number, it must be in milliseconds (adding "000" to your attributes). For example:

  • Date(1709269260) = Jan 20, 1970, 1:47:49 PM Eastern Standard Time
  • Date(1709269260000) = Mar 1, 2024, 12:01:00 AM Eastern Standard Time

If you want to use that field, then your expression should look like this

 

var started = Date($feature.closureStartEpoch + '000');
var closed = Date($feature.closureEndEpoch + '000');
var present = Date()
If (present >= started && present <= closed) return "Open"
return "Closed"

 

 

0 Kudos
JustinNettleton1
New Contributor III

Thanks for this. This helps. It kind of led me to a knew issue though. I don't want the Closed events to show on the map. I can change the symbol to be blank, but when I click on a feature that is Open, it could have 4 other features under it that are closed and show up in the popup. So is there anyway to just show the date for the Open events on the map and in the popup?  

 

I wish they we could just run arcade expressions in the filter tool. 

0 Kudos