tl;dr: use the number() function in the for-loop to cast existing date data into UNIX epoch time, this can be read by the esriFieldTypeDate as correct date. |
By trial and error I ended up trying the number() function on a date, which produces the UNIX epoch time, which is further down the line accepted by the esriFieldTypeDate in a dictionary.
I guess if there would have been an example showing this capabillity of the number() function in the documentation I would have found this solution way faster (google doesnt bring up anything useful either).
Maybe this could be inculded @DerekLaw ?
Well, here is an complete example of how to use the number() function in a way that keeps your exisiting date data alive:
var p = 'https://xxx';
var itemID = 'xxx';
var layerID = 0;
var fv = FeatureSetByPortalItem(Portal(p),itemID,layerID,
['start_time',
'BP3_weed_adoption_yn'],
false );
var dict = {
fields: [
{ name: 'start_time', type: 'esriFieldTypeDate' },
{ name: 'BP3_weed_adoption_yn', type: 'esriFieldTypeString' },
],
geometryType: '',
features: [],
};
var index = 0;
for (var feature in fv) {
dict.features[index] = {
'attributes': {
'start_time': Number(feature['start_time']),
'BP3_weed_adoption_yn': Text(feature['BP3_weed_adoption_yn'])
}}
index++;}
var fs_dict = FeatureSet(Text(dict));
return fs_dict
---