Skip to content

Commit eec2798

Browse files
committed
generate-tz-header.py: Fix position coordinate parsing.
We were reading zone.tab incorrectly, constructing a decimal value directly from the coordinate data. But described in the companion zone1970.tab file (tzdata package), the format is: # 2. Latitude and longitude of the timezone's principal location # in ISO 6709 sign-degrees-minutes-seconds format, # either ±DDMM±DDDMM or ±DDMMSS±DDDMMSS, # first latitude (+ is north), then longitude (+ is east). Update our script to parse and convert these coordinates into decimal values correctly. Fixes #415.
1 parent 789b2ee commit eec2798

File tree

2 files changed

+421
-424
lines changed

2 files changed

+421
-424
lines changed

plugins/color/generate-tz-header.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from argparse import ArgumentParser
55
from pathlib import Path
66

7-
COORDS_RE = re.compile(r"([+-])([0-9]+)([+-])([0-9]+)")
7+
COORDS_RE = re.compile(r"([+-]{1}[0-9]{2})([0-9]{2})([0-9]*)([+-]{1}[0-9]{3})([0-9]{2})([0-9]*)")
88

99
d = {}
1010

@@ -21,13 +21,10 @@
2121
continue
2222

2323
coords, tz = line.split('\t')[1:3]
24-
lat_sign, lat_val, long_sign, long_val = COORDS_RE.search(coords).groups()
24+
lat_deg, lat_min, lat_sec, long_deg, long_min, long_sec = COORDS_RE.search(coords).groups()
2525

26-
lat_str = lat_sign + lat_val[0:2] + "." + lat_val[2:]
27-
long_str = long_sign + long_val[0:3] + "." + long_val[3:]
28-
29-
lat = float(lat_str)
30-
long = float(long_str)
26+
lat = float(lat_deg + str((int(lat_min) / 60.0) + ((int(lat_sec) if lat_sec else 0) / 3600.0))[1:])
27+
long = float(long_deg + str((int(long_min) / 60.0) + ((int(long_sec) if long_sec else 0) / 3600.0))[1:])
3128

3229
d[tz] = [lat, long]
3330

0 commit comments

Comments
 (0)