Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

fix(fires): parse the detection time inside the tools package

Rudy Celekli224d71753b02
diff --git a/src/tools/queries/hazards.js b/src/tools/queries/hazards.js
index f644be562..194f9b8c1 100644
--- a/src/tools/queries/hazards.js
+++ b/src/tools/queries/hazards.js
@@ -1,11 +1,24 @@
/** Natural hazard queries: earthquakes and active fires. */
-import { acquisitionMsUtc } from '../../data/firmsCsv.js';
import { suggestView } from '../views.js';
import { defineTool, ToolError } from '../catalog.js';
import { AREA_SCHEMA, areaContains, resolveArea } from '../area.js';
import { LIMIT_SCHEMA, capRows, countNoun, isoTime } from '../results.js';
+function acquiredMsUtc(acqDate, acqTime) {
+ if (typeof acqDate !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(acqDate))
+ return NaN;
+ const timeText = String(acqTime ?? '').trim();
+ if (!/^\d{1,4}$/.test(timeText)) return NaN;
+ const hhmm = timeText.padStart(4, '0');
+ const hours = Number(hhmm.slice(0, 2));
+ const minutes = Number(hhmm.slice(2, 4));
+ if (hours > 23 || minutes > 59) return NaN;
+ return Date.parse(
+ `${acqDate}T${hhmm.slice(0, 2)}:${hhmm.slice(2, 4)}:00.000Z`,
+ );
+}
+
export const getEarthquakes = defineTool({
name: 'get_earthquakes',
title: 'Recent earthquakes',
@@ -115,7 +128,7 @@ export const getActiveFires = defineTool({
lon: fire.lon,
frp_mw: fire.frp ?? null,
confidence: fire.confidence ?? null,
- acquired: isoTime(acquisitionMsUtc(fire.acqDate, fire.acqTime)),
+ acquired: isoTime(acquiredMsUtc(fire.acqDate, fire.acqTime)),
satellite: fire.satellite ?? null,
day_night: fire.daynight ?? null,
})),