A METAR from Last Month
A METAR from Last Month
An archive import stamps each METAR with the time it was received, 2024-07-01T00:05:00Z. The report says 302350Z. What time was it issued?
The naive approach
// The naive approach: put the day, hour and minute in the current month
const received = new Date("2024-07-01T00:05:00Z");
const issued = new Date(Date.UTC(
received.getUTCFullYear(),
received.getUTCMonth(), // July
30, 23, 50,
));
// 2024-07-30T23:50:00Z — 30 days after the report was receivedWatch it break
The naive approach silently produces wrong results — there is no GMT equivalent to demonstrate because the failure is not using GMT.
Why
A METAR time group is a day, an hour and a minute. It names no month. The report was issued ten minutes before the end of 30 June and received after midnight, so the month the reader needs is the one before the month it was received in. Code that assumes the current month gets this right 29 or 30 days out of 30, and wrong for every report that crosses a month end, which is why it passes in testing. `parseMetarTime` takes the reference you state and chooses the candidate nearest it, so 30 June wins. It never reads the clock, so the same archive gives the same answer in any month.
The gmt approach
import { parseMetarTime } from "@northguild/gmt/aviation/parse";
parseMetarTime("302350Z", "2024-07-01T00:05:00Z");
// "2024-06-30T23:50:00Z"
parseMetarTime("312350Z", "2024-07-01T00:05:00Z");
// "2024-05-31T23:50:00Z" (June has no 31st)Same widget, working
The fix is to pass the time the report was received and let the function choose the month. See Aviation: Message Times for the rule, and Aviation mistakes for the others that come with it.
© 2026 NorthGuild · Licences
Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.