Arcade FeatureSets and Date Fields: What's Going On?

419
1
02-24-2022 02:59 PM
Labels (1)
jcarlson
MVP Esteemed Contributor

When creating a FeatureSet from a dictionary, as in Data Expressions in Dashboards, I cannot add a date to a date field.

In the simplest example, here's a single-feature set with a single field, which ought to have the current date/time in it.

 

 

var fs_dict = {
    fields: [{name: 'some_date', type: 'esriFieldTypeDate'}],
    geometryType: '',
    features: [
        {attributes: {some_date: Now()}}    
    ]
}

return FeatureSet(Text(fs_dict))

 

 

However, this returns an empty set.

Casting the date as a number, however, seems to work. Replace line 5 with the following:

{attributes: {some_date: Number(Now())}}

And it returns my feature!

jcarlson_0-1645742761727.png

I thought perhaps this was due to a difference in how the text-encoded datetime was being read. Leaving it as the datetime gives me 2022-02-24T22:48:57.371Z, whereas the number returns 1645742863932.

But cast either of those as a date, and it reads them both in just fine:

jcarlson_1-1645743022565.png

So what's going on in the FeatureSet function? Why can it not handle text dates?

To add another layer to this, I can't even take a feature from one set and pass it to another without losing the rows with dates.

 

 

var fs_dict = {
    fields: [{name: 'some_date', type: 'esriFieldTypeDate'}],
    geometryType: '',
    features: [
        {attributes: {some_date: Now()}},
        {attributes: {some_date: Null}}
    ]
}

var fs = FeatureSet(Text(fs_dict))

var second_dict = {
    fields: [{name: 'some_date', type: 'esriFieldTypeDate'}],
    geometryType: '',
    features: []
}

// Copy features from fs to dict
for (var f in fs){
    Push(second_dict['features'], f)
}

return FeatureSet(Text(second_dict))

 

 

Returns a one-row set with the null value, but not the Now.

The only way to pass features between sets is to cast them as a Number, but I can only do that by explicitly stating each attribute, rather than just passing the entire feature.

- Josh Carlson
Kendall County GIS
0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

Hi @jcarlson ,

There is something additional you need to do in order to create a valid featureset containing dates. The date has to be translated to a UNIX timestamp.  In the post below you can see an example: https://community.esri.com/t5/developers-questions/arcade-dictionary-to-featureset/td-p/1047117 

0 Kudos