We have a data stream that is displaying times in GMT. We would like to changed multiple to CST (-6 hours).
I see the Date functions in Arcade might work.
https://developers.arcgis.com/arcade/function-reference/date_functions/#tolocal
DateAdd shows this
var startDate = Date($feature.dateField);
var oneWeekLater = DateAdd(startDate, 7, 'days');
return oneWeekLater;
Can I change that to
var startDate = Date($feature.dateField);
var Sixhoursago = DateAdd(startDate, -6, 'hours');
return Sixhoursago;
I want to change all these fields.
Yes, date functions would be the way to go. Since you're doing this multiple times, you may also want to use a custom function.
function GMTtoCST(d){
return DateAdd(d, -6, 'hours')
}
var d1 = Now()
var d2 = Date('2022', '5', '27', '15')
var d3 = Date('2017', '8', '11', '8')
Console(d1, GMTtoCST(d1))
Console(d2, GMTtoCST(d2))
Console(d3, GMTtoCST(d3))
Thank You Josh!
This is a big help. I need a bit more help with it since I'm not to familiar with Arcade.
Do I replace d1-d3 with
{bcs_time_first_unit_assigned}
{bcs_time_first_unit_arrived}
{bcs_response_time_depart}?
How would I call the function in the line item template to have just CST show?
Thank you so much again Josh!
Up in the Advanced Formatting area, you'd add these converted times to the attributes section, like this:
function GMTtoCST(d){
return DateAdd(d, -6, 'hours')
}
return {
attributes: {
assigned: GMTtoCST($feature.bcs_time_first_unit_assigned),
arrived: GMTtoCST($feature.bcs_time_first_unit_arrived),
departed: GMTtoCST($feature.bcs_response_time_depart)
}
}
Then in your line item template, you pull out individual attributes like {expression/assigned} and so on.