@tak-ps/node-cot 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,10 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v2.7.0
14
+
15
+ - :rocket: Improved date parsing in CoT messages created using from_geojson
16
+
13
17
  ### v2.6.0
14
18
 
15
19
  - :tada: Add support for passing style properties via GeoJSON Properties
package/lib/util.js CHANGED
@@ -98,9 +98,11 @@ export default class Util {
98
98
  if (!start) start = new Date(now).toISOString();
99
99
 
100
100
  if (!stale) {
101
- stale = new Date(now + 20 * 1000).toISOString();
101
+ stale = new Date(new Date(start).getTime() + 20 * 1000).toISOString();
102
102
  } else if (!isNaN(parseInt(stale))) {
103
- stale = new Date(now + 20 * 1000).toISOString();
103
+ stale = new Date(new Date(start).getTime() + stale * 1000).toISOString();
104
+ } else if (typeof stale === 'string') {
105
+ stale = new Date(stale).toISOString();
104
106
  }
105
107
 
106
108
  return { time, start, stale };
package/lib/xml.js CHANGED
@@ -61,10 +61,13 @@ export default class XMLCot {
61
61
  if (feature.id) cot.event._attributes.uid = feature.id;
62
62
  if (feature.properties.callsign && !feature.id) cot.event._attributes.uid = feature.properties.callsign;
63
63
 
64
- for (const key of ['time', 'start', 'stale', 'type', 'how']) {
64
+ for (const key of ['type', 'how']) {
65
65
  if (feature.properties[key]) cot.event._attributes[key] = feature.properties[key];
66
66
  }
67
67
 
68
+ const dts = Util.cot_date(feature.properties.time, feature.properties.start, feature.properties.stale);
69
+ Object.assign(cot.event._attributes, dts);
70
+
68
71
  if (!feature.geometry) throw new Error('Must have Geometry');
69
72
  if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type)) throw new Error('Unsupported Geoemtry Type');
70
73