[content] Coyhaique: Trust only a country's own zones, and give southern Chile its own clocks

This commit is contained in:
2026-11-17 18:49:27 +01:00
parent 22f55dc9fa
commit c2320a4517
4 changed files with 32 additions and 4 deletions
+18 -1
View File
@@ -119,10 +119,27 @@ const d2 = (a: { lat: number; lon: number }, b: { lat: number; lon: number }): n
*/
function trustedZone(neZone: string, country: string, lat: number, lon: number): string | null {
if (!neZone || !validZone(neZone) || !fitsLongitude(neZone, lon)) return null;
// Another country's own zone is never trusted, however alike its clock: Natural Earth
// files Santiago under America/Sao_Paulo, whose fixed UTC-3 matched Chile's fixed-clock
// southern zones and moved the capital off its own clock (2026-11-17).
const owner = tz.get(neZone);
if (owner && !owner.countries.includes(country)) return null;
const same = countryZones(country).filter((z) => clockOf(z.zone) === clockOf(neZone));
return same.sort((a, b) => d2({ lat, lon }, a) - d2({ lat, lon }, b))[0]?.zone ?? null;
}
/**
* Regions that left their country's main clock after Natural Earth's data was made, by
* latitude along the region's borders. Source: the time zone database's zone1970.tab
* ("Aysén Region", "Magallanes Region") and the regions' borders. Mainland only.
*/
const REGION_BANDS: readonly { country: string; zone: string; south: number; north: number; west: number }[] = [
{ country: 'CL', zone: 'America/Coyhaique', north: -43.7, south: -49.0, west: -76 },
{ country: 'CL', zone: 'America/Punta_Arenas', north: -49.0, south: -56.5, west: -76 }
];
const bandZone = (country: string, lat: number, lon: number): string | null =>
REGION_BANDS.find((b) => b.country === country && lat <= b.north && lat > b.south && lon >= b.west && validZone(b.zone))?.zone ?? null;
/** A name field that a fixed-width DBF did not cut in the middle of a letter. */
const clean = (s: string | undefined): string => (s && !s.includes('�') ? s : '');
@@ -157,7 +174,7 @@ for (const r of raw) {
continue;
}
const country = r['ISO_A2'] === '-99' ? (CLOCK_COUNTRY[r['ADM0NAME'] ?? ''] ?? '') : (r['ISO_A2'] ?? '');
towns.push({ r, name, country, lat, lon, zone: trustedZone(r['TIMEZONE'] ?? '', country, lat, lon) });
towns.push({ r, name, country, lat, lon, zone: bandZone(country, lat, lon) ?? trustedZone(r['TIMEZONE'] ?? '', country, lat, lon) });
}
// A town without a trusted zone takes the zone most of its five nearest trusted