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

The tools package cannot import firmsCsv. Pad the FIRMS clock here so 00:45 UTC still reads as 00:45.
This commit is contained in:
Rudy Celekli committed 2026-10-25 16:01:26 -04:00
1 parent 57df5f61ba
commit 224d71753b
1 file changed
+15 -2
+15 -2
View File
@@ -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,
})),