mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
fix(airports): use Bahrain time for Bahrain flights
Correct the airport data and repair affected flight endpoints and metadata during upgrade. Preserve stored local flight times and legacy metadata encoding. Closes #3294
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
// Build server/assets/airports.json from OurAirports (davidmegginson.github.io/ourairports-data).
|
||||
// License: Public Domain. Keeps large/medium airports with an IATA code, small ones only with scheduled service;
|
||||
// timezone derived from coords via tz-lookup.
|
||||
// Timezones come from coordinates via tz-lookup, with known country corrections.
|
||||
import fs from 'node:fs';
|
||||
import https from 'node:https';
|
||||
import path from 'node:path';
|
||||
@@ -11,6 +11,8 @@ import tzLookup from 'tz-lookup';
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const OUT = path.join(__dirname, '..', 'assets', 'airports.json');
|
||||
const SRC = 'https://davidmegginson.github.io/ourairports-data/airports.csv';
|
||||
// The coordinate lookup places Bahrain's airport in Iran. Bahrain has one zone.
|
||||
const COUNTRY_TIMEZONE_OVERRIDES = new Map([['BH', 'Asia/Bahrain']]);
|
||||
|
||||
function fetchText(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -97,11 +99,12 @@ for (let i = 1; i < rows.length; i++) {
|
||||
if (r[TYPE] === 'small_airport' && r[SERVICE] !== 'yes') continue;
|
||||
const lat = Number(r[LAT]);
|
||||
const lng = Number(r[LNG]);
|
||||
const country = r[COUNTRY] || '';
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lng)) continue;
|
||||
|
||||
let tz = null;
|
||||
try {
|
||||
tz = tzLookup(lat, lng);
|
||||
tz = COUNTRY_TIMEZONE_OVERRIDES.get(country) ?? tzLookup(lat, lng);
|
||||
} catch {
|
||||
skippedNoTz++;
|
||||
continue;
|
||||
@@ -116,7 +119,7 @@ for (let i = 1; i < rows.length; i++) {
|
||||
icao: r[ICAO]?.trim().toUpperCase() || null,
|
||||
name: r[NAME],
|
||||
city: r[MUNICIPALITY] || '',
|
||||
country: r[COUNTRY] || '',
|
||||
country,
|
||||
lat: Math.round(lat * 1e6) / 1e6,
|
||||
lng: Math.round(lng * 1e6) / 1e6,
|
||||
tz,
|
||||
@@ -141,7 +144,7 @@ const previous = fs.existsSync(OUT) ? JSON.parse(fs.readFileSync(OUT, 'utf8')) :
|
||||
let kept = 0;
|
||||
for (const a of previous) {
|
||||
if (seen.has(a.iata)) continue;
|
||||
seen.set(a.iata, a);
|
||||
seen.set(a.iata, { ...a, tz: COUNTRY_TIMEZONE_OVERRIDES.get(a.country) ?? a.tz });
|
||||
kept++;
|
||||
}
|
||||
const unique = Array.from(seen.values()).sort((a, b) => a.iata.localeCompare(b.iata));
|
||||
|
||||
Reference in New Issue
Block a user