# Aviation mistakes

Industry: Aviation

The Aviation layer reads and writes the dates in airline schedule files, and reads the times in
weather reports and notices to air missions. The mistakes around them are the ones a quick parser
makes: reading the month letters as a word in the machine's language,
accepting lower case, fixing a century in code, writing a year the reader will place in another
century, and judging a leap day without knowing the century. A METAR time has no month, and a
NOTAM can end in a word or an estimate, so there are three more: assuming the current month,
turning `PERM` into a date and dropping `EST`. Every output shown here is what the function
returns.

## Month letters

### Reading the month through the locale

Severity: high.

The three letters of an SSIM month are a fixed English code. A pattern parser given the platform's language rejects JAN on a machine set to Spanish and accepts ENE, which no file writes. parseSsimDate reads a constant table and never asks for a language.

Wrong:
```js
import { parseDateWithPattern } from "@northguild/gmt/plain/parse";

const locale = "es-ES"; // what the platform reports on this server

parseDateWithPattern("01JAN26", "ddMMMyy", locale, { yearWindow: 2000 });
// "" — the code is read as a Spanish word
```

Right:
```js
import { parseSsimDate } from "@northguild/gmt/aviation/parse";

parseSsimDate("01JAN26", { yearWindow: 2000 });
// "2026-01-01"
parseSsimDate("01ENE26", { yearWindow: 2000 });
// ""
```

### Accepting lower case

Severity: medium.

SSIM writes the month letters in upper case. A parser that ignores case accepts jan, so a writer built beside it emits jan, and a file the other side rejects. parseSsimDate takes upper case only.

Wrong:
```js
import { parseDateWithPattern } from "@northguild/gmt/plain/parse";

parseDateWithPattern("01jan26", "ddMMMyy", "en", { yearWindow: 2000 });
// "2026-01-01" — a spelling no SSIM file writes
```

Right:
```js
import { parseSsimDate } from "@northguild/gmt/aviation/parse";

parseSsimDate("01jan26", { yearWindow: 2000 });
// ""
parseSsimDate("01Jan26", { yearWindow: 2000 });
// ""
parseSsimDate("01JAN26", { yearWindow: 2000 });
// "2026-01-01"
```

## The century

### A century pivot fixed in code

Severity: high.

A rule such as 'a year under 70 is 20xx' is right for the files of one period and wrong for the rest, and it flips the day it is passed. The century is a fact about your files. parseSsimDate takes the window you state, and gives nothing without one.

Wrong:
```js
const yy = 26;
const year = yy < 70 ? 2000 + yy : 1900 + yy;
// 2026 — and 01JAN70 in an archive from the 2070s is read as 1970
```

Right:
```js
import { parseSsimDate } from "@northguild/gmt/aviation/parse";

parseSsimDate("01JAN70", { yearWindow: 1970 });
// "1970-01-01"
parseSsimDate("01JAN70", { yearWindow: 1971 });
// "2070-01-01"
parseSsimDate("01JAN70", {});
// ""
```

### Formatting a year outside the window

Severity: high.

Writing a year as two digits drops its century. If the reader's window does not hold that year, it reads back as another one. formatSsimDate refuses a year outside the window you state, so what it writes reads back as the same date, with the same window.

Wrong:
```js
const year = 2100;
String(year).slice(-2);
// "00" — which a reader with a window from 2000 places in 2000
```

Right:
```js
import { formatSsimDate } from "@northguild/gmt/aviation/format";

formatSsimDate("2100-01-01", { yearWindow: 2000 });
// ""
formatSsimDate("2026-01-01", { yearWindow: 2000 });
// "01JAN26"
```

### Validating without the window

Severity: medium.

Whether 29FEB00 exists depends on the century: 2000 was a leap year and 1900 was not. A check that never asks for the window cannot answer. isValidSsimDate takes the window, and is false without one.

Wrong:
```js
// a pattern that checks the shape and day 1 to 31
/^(0[1-9]|[12][0-9]|3[01])(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)[0-9]{2}$/.test("29FEB00");
// true — in which century?
```

Right:
```js
import { isValidSsimDate } from "@northguild/gmt/aviation/validate";

isValidSsimDate("29FEB00", { yearWindow: 2000 });
// true
isValidSsimDate("29FEB00", { yearWindow: 1900 });
// false
isValidSsimDate("29FEB00", {});
// false
```

## The METAR time

### Assuming the current month

Severity: high.

A METAR time group is a day, an hour and a minute, with no month. Putting it in the month the report was received gives a time 30 days ahead for any report that crosses a month end. parseMetarTime takes the time the report was received and chooses the nearest candidate.

Wrong:
```js
const received = new Date("2024-07-01T00:05:00Z");

new Date(Date.UTC(received.getUTCFullYear(), received.getUTCMonth(), 30, 23, 50));
// 2024-07-30T23:50:00Z — the report was issued on 30 June
```

Right:
```js
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"
parseMetarTime("302350Z", "");
// ""
```

## NOTAM validity

### PERM as a date

Severity: high.

PERM says a NOTAM has no end. A far-future date makes 'is it in force?' right until that day, and gives the NOTAM an expiry it never stated. parseNotamValidity returns { kind: 'permanent' }, which has nothing to compare.

Wrong:
```js
const end = c === "PERM" ? "9999-12-31T23:59:00Z" : toIso(c);
// a date for something that has no end
```

Right:
```js
import { parseNotamValidity } from "@northguild/gmt/aviation/parse";

parseNotamValidity("PERM", { yearWindow: 2000 });
// { kind: "permanent" }
parseNotamValidity("2506151200", { yearWindow: 2000 });
// { kind: "instant", instant: "2025-06-15T12:00:00Z", estimated: false }
```

### Dropping EST

Severity: medium.

EST after the ten digits says the end is an estimate and the NOTAM may be replaced or cancelled first. Cutting it off with slice(0, 10) shows a guess as a promise. parseNotamValidity keeps the instant and sets estimated: true.

Wrong:
```js
const end = value.slice(0, 10); // "1407031230EST" becomes "1407031230"
// the estimate is now a firm end time
```

Right:
```js
import { parseNotamValidity } from "@northguild/gmt/aviation/parse";

parseNotamValidity("1407031230EST", { yearWindow: 2000 });
// { kind: "instant", instant: "2014-07-03T12:30:00Z", estimated: true }
parseNotamValidity("1407031230 EST", { yearWindow: 2000 });
// null
```

See [An SSIM Month Read in the Wrong
Language](/gmt/scenarios/an-ssim-month-read-in-the-wrong-language/), [A METAR from Last
Month](/gmt/scenarios/a-metar-from-last-month/), [PERM Read as a Date](/gmt/scenarios/perm-read-as-a-date/), and the reasoning in [Aviation:
Message Times](/gmt/guides/industries/aviation-message-times/). To try a date yourself, use the
[SSIM Date Reader](/gmt/tools/ssim-date-reader/).
