[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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+12 -1
View File
@@ -45,7 +45,18 @@ describe('the town list', () => {
['Anchorage', 'United States of America', 'America/Anchorage'], // Natural Earth: America/Juneau
['Kryvyi Rih', 'Ukraine', 'Europe/Kyiv'], // never Simferopol's Moscow time
['Apia', 'Samoa', 'Pacific/Apia'], // UTC+13 at 172° W
['Pristina', 'Kosovo', 'Europe/Belgrade'] // no ISO code in Natural Earth
['Pristina', 'Kosovo', 'Europe/Belgrade'], // no ISO code in Natural Earth
// Natural Earth: America/Sao_Paulo, whose fixed UTC-3 once moved the capital onto a
// southern zone's clock with no daylight saving (fixed 2026-11-17).
['Santiago', 'Chile', 'America/Santiago'],
['Valparaíso', 'Chile', 'America/Santiago'],
['Puerto Montt', 'Chile', 'America/Santiago'], // north of Aysén: the main clock
// Natural Earth predates the regional splits (Magallanes 2016, Aysén 2025).
['Coyhaique', 'Chile', 'America/Coyhaique'],
['Puerto Aisén', 'Chile', 'America/Coyhaique'],
["Villa O'Higgins", 'Chile', 'America/Coyhaique'], // Natural Earth even files it under Argentina's Santa Cruz
['Punta Arenas', 'Chile', 'America/Punta_Arenas'],
['Puerto Williams', 'Chile', 'America/Punta_Arenas']
])('%s, %s, keeps %s', (name, country, zone) => {
const t = towns.find((x) => x.name === name && x.country === country);
expect(t?.timeZone).toBe(zone);
+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