Simplify UTC offset ID data by computing the offsets
It's trivial to do - and done when generating our compiled data tables, so makes no difference to users - but makes the offset list table simpler. Reformat the list so that the fragment-of-hour offsets are clearly distinguished from the whole-hour ones. Change-Id: I6e0ea23dc317542b3256e88492e4073faedef1d7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
08c877a703
commit
b48b4f4d3b
@ -111,9 +111,21 @@ class ZoneIdWriter (SourceFileEditor):
|
||||
pair[1], pair[0]))
|
||||
out('};\n\n')
|
||||
|
||||
def offsetOf(utcName):
|
||||
"Maps a UTC±HH:mm name to its offset in seconds"
|
||||
assert utcName.startswith('UTC')
|
||||
if len(utcName) == 3:
|
||||
return 0
|
||||
assert utcName[3] in '+-', utcName
|
||||
sign = -1 if utcName[3] == '-' else 1
|
||||
assert len(utcName) == 9 and utcName[6] == ':', utcName
|
||||
hour, mins = int(utcName[4:6]), int(utcName[-2:])
|
||||
return sign * (hour * 60 + mins) * 60
|
||||
|
||||
offsetMap = {}
|
||||
for pair in utcIdList:
|
||||
offsetMap[pair[1]] = offsetMap.get(pair[1], ()) + (pair[0],)
|
||||
for name in utcIdList:
|
||||
offset = offsetOf(name)
|
||||
offsetMap[offset] = offsetMap.get(offset, ()) + (name,)
|
||||
# Write UTC ID key table
|
||||
out('// IANA ID Index, UTC Offset\n')
|
||||
out('static constexpr UtcData utcDataTable[] = {\n')
|
||||
@ -192,7 +204,7 @@ def main(out, err):
|
||||
f'UTC+{h:02}:{m:02}'
|
||||
for h, m in (divmod(o, 60) for o in winOff if o > 0))
|
||||
# All such offsets should be represented by entries in utcIdList:
|
||||
newUtc = winUtc.difference(n for n, o in utcIdList)
|
||||
newUtc = winUtc.difference(utcIdList)
|
||||
if newUtc:
|
||||
err.write(f'Please add {", ".join(newUtc)} to zonedata.utcIdList\n')
|
||||
return 1
|
||||
|
@ -21,8 +21,7 @@ When adding an entry to windowsIdList, check whether its offset
|
||||
corresponds to that of some entry in utcIdList; if not, add such an
|
||||
entry.
|
||||
|
||||
The utcIdList is again a list of tuples (name, offset), associating
|
||||
various UTC-offset names with their offsets in seconds. Aside from
|
||||
The utcIdList is a simple list of various UTC-offset names. Aside from
|
||||
'UTC' itself, shared with windowsIdList, these include minutes in
|
||||
their offsets even when they are whole hour offsets. The list contains
|
||||
the UTC-equivalents of all offsets seen in the windowsIdList, plus the
|
||||
@ -50,52 +49,37 @@ backwards compatibility.
|
||||
|
||||
# Do not remove IDs, as each entry is part of the API/behavior guarantee.
|
||||
# IDs for the same offset shall be space-joined; list the preferred ID first.
|
||||
# ( UTC Id, Offset Seconds )
|
||||
utcIdList = (
|
||||
('UTC-14:00', -50400),
|
||||
('UTC-13:00', -46800),
|
||||
('UTC-12:00', -43200),
|
||||
('UTC-11:00', -39600),
|
||||
('UTC-10:00', -36000),
|
||||
('UTC-09:30', -34200),
|
||||
('UTC-09:00', -32400),
|
||||
('UTC-08:00', -28800),
|
||||
('UTC-07:00', -25200),
|
||||
('UTC-06:00', -21600),
|
||||
('UTC-05:00', -18000),
|
||||
('UTC-04:30', -16200),
|
||||
('UTC-04:00', -14400),
|
||||
('UTC-03:30', -12600),
|
||||
('UTC-03:00', -10800),
|
||||
('UTC-02:00', -7200),
|
||||
('UTC-01:00', -3600),
|
||||
('UTC', 0), # Goes first (among zero-offset) to be default
|
||||
('UTC+00:00', 0),
|
||||
('UTC-00:00', 0), # Should recognize, but avoid using (see Note above).
|
||||
('UTC+01:00', 3600),
|
||||
('UTC+02:00', 7200),
|
||||
('UTC+03:00', 10800),
|
||||
('UTC+03:30', 12600),
|
||||
('UTC+04:00', 14400),
|
||||
('UTC+04:30', 16200),
|
||||
('UTC+05:00', 18000),
|
||||
('UTC+05:30', 19800),
|
||||
('UTC+05:45', 20700),
|
||||
('UTC+06:00', 21600),
|
||||
('UTC+06:30', 23400),
|
||||
('UTC+07:00', 25200),
|
||||
('UTC+08:00', 28800),
|
||||
('UTC+08:30', 30600),
|
||||
('UTC+08:45', 31500),
|
||||
('UTC+09:00', 32400),
|
||||
('UTC+09:30', 34200),
|
||||
('UTC+10:00', 36000),
|
||||
('UTC+10:30', 37800),
|
||||
('UTC+11:00', 39600),
|
||||
('UTC+12:00', 43200),
|
||||
('UTC+12:45', 45900),
|
||||
('UTC+13:00', 46800),
|
||||
('UTC+14:00', 50400),
|
||||
'UTC-14:00',
|
||||
'UTC-13:00',
|
||||
'UTC-12:00',
|
||||
'UTC-11:00',
|
||||
'UTC-10:00', 'UTC-09:30',
|
||||
'UTC-09:00',
|
||||
'UTC-08:00',
|
||||
'UTC-07:00',
|
||||
'UTC-06:00',
|
||||
'UTC-05:00', 'UTC-04:30',
|
||||
'UTC-04:00', 'UTC-03:30',
|
||||
'UTC-03:00',
|
||||
'UTC-02:00',
|
||||
'UTC-01:00',
|
||||
# UTC Goes first (among zero-offset) to be default:
|
||||
'UTC', 'UTC+00:00', 'UTC-00:00',
|
||||
'UTC+01:00',
|
||||
'UTC+02:00',
|
||||
'UTC+03:00', 'UTC+03:30',
|
||||
'UTC+04:00', 'UTC+04:30',
|
||||
'UTC+05:00', 'UTC+05:30', 'UTC+05:45',
|
||||
'UTC+06:00', 'UTC+06:30',
|
||||
'UTC+07:00',
|
||||
'UTC+08:00', 'UTC+08:30', 'UTC+08:45',
|
||||
'UTC+09:00', 'UTC+09:30',
|
||||
'UTC+10:00', 'UTC+10:30',
|
||||
'UTC+11:00',
|
||||
'UTC+12:00', 'UTC+12:45',
|
||||
'UTC+13:00',
|
||||
'UTC+14:00',
|
||||
)
|
||||
|
||||
# ( Windows Id, Offset Seconds )
|
||||
|
Loading…
x
Reference in New Issue
Block a user