2021-07-05 15:45:26 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-05-10 10:06:48 +00:00
|
|
|
# Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2017-05-23 13:24:35 +00:00
|
|
|
"""Parse CLDR data for QTimeZone use with MS-Windows
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-10-08 12:02:18 +00:00
|
|
|
Script to parse the CLDR common/supplemental/windowsZones.xml file and
|
2022-10-17 08:58:31 +00:00
|
|
|
prepare its data for use in QTimeZone. See ``./cldr2qlocalexml.py`` for
|
|
|
|
where to get the CLDR data. Pass its root directory as first parameter
|
|
|
|
to this script. You can optionally pass the qtbase root directory as
|
|
|
|
second parameter; it defaults to the root of the checkout containing
|
|
|
|
this script. This script updates qtbase's
|
|
|
|
src/corelib/time/qtimezoneprivate_data_p.h with the new data.
|
2017-05-23 13:24:35 +00:00
|
|
|
"""
|
2013-01-27 13:52:56 +00:00
|
|
|
|
|
|
|
import datetime
|
2021-07-09 13:34:40 +00:00
|
|
|
from pathlib import Path
|
2020-02-27 09:56:36 +00:00
|
|
|
import textwrap
|
2021-07-07 10:41:10 +00:00
|
|
|
import argparse
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2022-10-17 08:58:31 +00:00
|
|
|
from localetools import unicode2hex, wrap_list, Error, SourceFileEditor, qtbase_root
|
2020-02-27 09:56:36 +00:00
|
|
|
from cldr import CldrAccess
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
### Data that may need updates in response to new entries in the CLDR file ###
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-10-08 12:02:18 +00:00
|
|
|
# This script shall report the updates you need to make, if any arise.
|
2020-02-19 15:10:45 +00:00
|
|
|
# However, you may need to research the relevant zone's standard offset.
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2019-05-28 14:21:15 +00:00
|
|
|
# List of currently known Windows IDs.
|
|
|
|
# If this script reports missing IDs, please add them here.
|
|
|
|
# Look up the offset using (google and) timeanddate.com.
|
|
|
|
# Not public so may safely be changed. Please keep in alphabetic order by ID.
|
|
|
|
# ( Windows Id, Offset Seconds )
|
|
|
|
windowsIdList = (
|
2021-07-05 16:04:41 +00:00
|
|
|
('Afghanistan Standard Time', 16200),
|
|
|
|
('Alaskan Standard Time', -32400),
|
|
|
|
('Aleutian Standard Time', -36000),
|
|
|
|
('Altai Standard Time', 25200),
|
|
|
|
('Arab Standard Time', 10800),
|
|
|
|
('Arabian Standard Time', 14400),
|
|
|
|
('Arabic Standard Time', 10800),
|
|
|
|
('Argentina Standard Time', -10800),
|
|
|
|
('Astrakhan Standard Time', 14400),
|
|
|
|
('Atlantic Standard Time', -14400),
|
|
|
|
('AUS Central Standard Time', 34200),
|
|
|
|
('Aus Central W. Standard Time', 31500),
|
|
|
|
('AUS Eastern Standard Time', 36000),
|
|
|
|
('Azerbaijan Standard Time', 14400),
|
|
|
|
('Azores Standard Time', -3600),
|
|
|
|
('Bahia Standard Time', -10800),
|
|
|
|
('Bangladesh Standard Time', 21600),
|
|
|
|
('Belarus Standard Time', 10800),
|
|
|
|
('Bougainville Standard Time', 39600),
|
|
|
|
('Canada Central Standard Time', -21600),
|
|
|
|
('Cape Verde Standard Time', -3600),
|
|
|
|
('Caucasus Standard Time', 14400),
|
|
|
|
('Cen. Australia Standard Time', 34200),
|
|
|
|
('Central America Standard Time', -21600),
|
|
|
|
('Central Asia Standard Time', 21600),
|
|
|
|
('Central Brazilian Standard Time', -14400),
|
|
|
|
('Central Europe Standard Time', 3600),
|
|
|
|
('Central European Standard Time', 3600),
|
|
|
|
('Central Pacific Standard Time', 39600),
|
|
|
|
('Central Standard Time (Mexico)', -21600),
|
|
|
|
('Central Standard Time', -21600),
|
|
|
|
('China Standard Time', 28800),
|
|
|
|
('Chatham Islands Standard Time', 45900),
|
|
|
|
('Cuba Standard Time', -18000),
|
|
|
|
('Dateline Standard Time', -43200),
|
|
|
|
('E. Africa Standard Time', 10800),
|
|
|
|
('E. Australia Standard Time', 36000),
|
|
|
|
('E. Europe Standard Time', 7200),
|
|
|
|
('E. South America Standard Time', -10800),
|
|
|
|
('Easter Island Standard Time', -21600),
|
|
|
|
('Eastern Standard Time', -18000),
|
|
|
|
('Eastern Standard Time (Mexico)', -18000),
|
|
|
|
('Egypt Standard Time', 7200),
|
|
|
|
('Ekaterinburg Standard Time', 18000),
|
|
|
|
('Fiji Standard Time', 43200),
|
|
|
|
('FLE Standard Time', 7200),
|
|
|
|
('Georgian Standard Time', 14400),
|
|
|
|
('GMT Standard Time', 0),
|
|
|
|
('Greenland Standard Time', -10800),
|
|
|
|
('Greenwich Standard Time', 0),
|
|
|
|
('GTB Standard Time', 7200),
|
|
|
|
('Haiti Standard Time', -18000),
|
|
|
|
('Hawaiian Standard Time', -36000),
|
|
|
|
('India Standard Time', 19800),
|
|
|
|
('Iran Standard Time', 12600),
|
|
|
|
('Israel Standard Time', 7200),
|
|
|
|
('Jordan Standard Time', 7200),
|
|
|
|
('Kaliningrad Standard Time', 7200),
|
|
|
|
('Korea Standard Time', 32400),
|
|
|
|
('Libya Standard Time', 7200),
|
|
|
|
('Line Islands Standard Time', 50400),
|
|
|
|
('Lord Howe Standard Time', 37800),
|
|
|
|
('Magadan Standard Time', 36000),
|
|
|
|
('Magallanes Standard Time', -10800), # permanent DST
|
|
|
|
('Marquesas Standard Time', -34200),
|
|
|
|
('Mauritius Standard Time', 14400),
|
|
|
|
('Middle East Standard Time', 7200),
|
|
|
|
('Montevideo Standard Time', -10800),
|
|
|
|
('Morocco Standard Time', 0),
|
|
|
|
('Mountain Standard Time (Mexico)', -25200),
|
|
|
|
('Mountain Standard Time', -25200),
|
|
|
|
('Myanmar Standard Time', 23400),
|
|
|
|
('N. Central Asia Standard Time', 21600),
|
|
|
|
('Namibia Standard Time', 3600),
|
|
|
|
('Nepal Standard Time', 20700),
|
|
|
|
('New Zealand Standard Time', 43200),
|
|
|
|
('Newfoundland Standard Time', -12600),
|
|
|
|
('Norfolk Standard Time', 39600),
|
|
|
|
('North Asia East Standard Time', 28800),
|
|
|
|
('North Asia Standard Time', 25200),
|
|
|
|
('North Korea Standard Time', 30600),
|
|
|
|
('Omsk Standard Time', 21600),
|
|
|
|
('Pacific SA Standard Time', -10800),
|
|
|
|
('Pacific Standard Time', -28800),
|
|
|
|
('Pacific Standard Time (Mexico)', -28800),
|
|
|
|
('Pakistan Standard Time', 18000),
|
|
|
|
('Paraguay Standard Time', -14400),
|
|
|
|
('Qyzylorda Standard Time', 18000), # a.k.a. Kyzylorda, in Kazakhstan
|
|
|
|
('Romance Standard Time', 3600),
|
|
|
|
('Russia Time Zone 3', 14400),
|
|
|
|
('Russia Time Zone 10', 39600),
|
|
|
|
('Russia Time Zone 11', 43200),
|
|
|
|
('Russian Standard Time', 10800),
|
|
|
|
('SA Eastern Standard Time', -10800),
|
|
|
|
('SA Pacific Standard Time', -18000),
|
|
|
|
('SA Western Standard Time', -14400),
|
|
|
|
('Saint Pierre Standard Time', -10800), # New France
|
|
|
|
('Sakhalin Standard Time', 39600),
|
|
|
|
('Samoa Standard Time', 46800),
|
|
|
|
('Sao Tome Standard Time', 0),
|
|
|
|
('Saratov Standard Time', 14400),
|
|
|
|
('SE Asia Standard Time', 25200),
|
|
|
|
('Singapore Standard Time', 28800),
|
|
|
|
('South Africa Standard Time', 7200),
|
2021-11-05 12:26:10 +00:00
|
|
|
('South Sudan Standard Time', 7200),
|
2021-07-05 16:04:41 +00:00
|
|
|
('Sri Lanka Standard Time', 19800),
|
|
|
|
('Sudan Standard Time', 7200), # unless they mean South Sudan, +03:00
|
|
|
|
('Syria Standard Time', 7200),
|
|
|
|
('Taipei Standard Time', 28800),
|
|
|
|
('Tasmania Standard Time', 36000),
|
|
|
|
('Tocantins Standard Time', -10800),
|
|
|
|
('Tokyo Standard Time', 32400),
|
|
|
|
('Tomsk Standard Time', 25200),
|
|
|
|
('Tonga Standard Time', 46800),
|
|
|
|
('Transbaikal Standard Time', 32400), # Yakutsk
|
|
|
|
('Turkey Standard Time', 7200),
|
|
|
|
('Turks And Caicos Standard Time', -14400),
|
|
|
|
('Ulaanbaatar Standard Time', 28800),
|
|
|
|
('US Eastern Standard Time', -18000),
|
|
|
|
('US Mountain Standard Time', -25200),
|
|
|
|
('UTC-11', -39600),
|
|
|
|
('UTC-09', -32400),
|
|
|
|
('UTC-08', -28800),
|
|
|
|
('UTC-02', -7200),
|
|
|
|
('UTC', 0),
|
|
|
|
('UTC+12', 43200),
|
|
|
|
('UTC+13', 46800),
|
|
|
|
('Venezuela Standard Time', -16200),
|
|
|
|
('Vladivostok Standard Time', 36000),
|
|
|
|
('Volgograd Standard Time', 14400),
|
|
|
|
('W. Australia Standard Time', 28800),
|
|
|
|
('W. Central Africa Standard Time', 3600),
|
|
|
|
('W. Europe Standard Time', 3600),
|
|
|
|
('W. Mongolia Standard Time', 25200), # Hovd
|
|
|
|
('West Asia Standard Time', 18000),
|
|
|
|
('West Bank Standard Time', 7200),
|
|
|
|
('West Pacific Standard Time', 36000),
|
|
|
|
('Yakutsk Standard Time', 32400),
|
|
|
|
('Yukon Standard Time', -25200), # Non-DST Mountain Standard Time since 2020-11-01
|
2019-05-28 14:21:15 +00:00
|
|
|
)
|
2013-01-27 13:52:56 +00:00
|
|
|
|
|
|
|
# List of standard UTC IDs to use. Not public so may be safely changed.
|
2019-05-28 14:21:15 +00:00
|
|
|
# Do not remove IDs, as each entry is part of the API/behavior guarantee.
|
Convert UTC offset table look-ups to binary chop
The table was almost sorted by offset - its UTC entry, with offset 0,
was at the front rather than first among the offset 0 entries. The
lookups in it were being done as if the IDs were in space-joined lists
(as for the IANA IDs in the Windows table), splitting on space,
despite the fact that it had separate entries for different IDs at the
same offset (this only arose for offset 0). So actually massage the
input table in python to combine IDs with the same offset using space,
placing UTC first among the offset 0 entries, and ensure the C++ table
is sorted. Regenerated the CLDR data tables using the updated script.
In the process, fix an off-by-one error in the iteration over
space-joined IDs, where the search only advanced to the space, rather
than to just after it. That wasn't a problem before, but now would be.
Change-Id: Ib49c27bac269b557166fa10738c3e396d58456c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-30 12:35:48 +00:00
|
|
|
# IDs for the same offset shall be space-joined; list the preferred ID first.
|
2019-05-28 14:21:15 +00:00
|
|
|
# ( UTC Id, Offset Seconds )
|
|
|
|
utcIdList = (
|
2021-07-05 16:04:41 +00:00
|
|
|
('UTC-14:00', -50400),
|
|
|
|
('UTC-13:00', -46800),
|
|
|
|
('UTC-12:00', -43200),
|
|
|
|
('UTC-11:00', -39600),
|
|
|
|
('UTC-10:00', -36000),
|
|
|
|
('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),
|
Convert UTC offset table look-ups to binary chop
The table was almost sorted by offset - its UTC entry, with offset 0,
was at the front rather than first among the offset 0 entries. The
lookups in it were being done as if the IDs were in space-joined lists
(as for the IANA IDs in the Windows table), splitting on space,
despite the fact that it had separate entries for different IDs at the
same offset (this only arose for offset 0). So actually massage the
input table in python to combine IDs with the same offset using space,
placing UTC first among the offset 0 entries, and ensure the C++ table
is sorted. Regenerated the CLDR data tables using the updated script.
In the process, fix an off-by-one error in the iteration over
space-joined IDs, where the search only advanced to the space, rather
than to just after it. That wasn't a problem before, but now would be.
Change-Id: Ib49c27bac269b557166fa10738c3e396d58456c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-30 12:35:48 +00:00
|
|
|
('UTC', 0), # Goes first (among zero-offset) to be default
|
2021-07-05 16:04:41 +00:00
|
|
|
('UTC+00:00', 0),
|
Convert UTC offset table look-ups to binary chop
The table was almost sorted by offset - its UTC entry, with offset 0,
was at the front rather than first among the offset 0 entries. The
lookups in it were being done as if the IDs were in space-joined lists
(as for the IANA IDs in the Windows table), splitting on space,
despite the fact that it had separate entries for different IDs at the
same offset (this only arose for offset 0). So actually massage the
input table in python to combine IDs with the same offset using space,
placing UTC first among the offset 0 entries, and ensure the C++ table
is sorted. Regenerated the CLDR data tables using the updated script.
In the process, fix an off-by-one error in the iteration over
space-joined IDs, where the search only advanced to the space, rather
than to just after it. That wasn't a problem before, but now would be.
Change-Id: Ib49c27bac269b557166fa10738c3e396d58456c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-30 12:35:48 +00:00
|
|
|
('UTC-00:00', 0), # Should recognize, but avoid using (see Note below).
|
2021-07-05 16:04:41 +00:00
|
|
|
('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+09:00', 32400),
|
|
|
|
('UTC+09:30', 34200),
|
|
|
|
('UTC+10:00', 36000),
|
|
|
|
('UTC+11:00', 39600),
|
|
|
|
('UTC+12:00', 43200),
|
|
|
|
('UTC+13:00', 46800),
|
|
|
|
('UTC+14:00', 50400),
|
2019-05-28 14:21:15 +00:00
|
|
|
)
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
### End of data that may need updates in response to CLDR ###
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2023-10-27 11:46:21 +00:00
|
|
|
# Note: -00:00 (without the UTC prefix) was introduced in RFC3339 as a
|
|
|
|
# way to indicate that a date-time has been converted to UTC but its
|
|
|
|
# use should not be understood to say anything about the local time of
|
|
|
|
# the origin of the message using it. However, ISO 8601 has, since
|
|
|
|
# 2000, forbidden this as an offset suffix. The more recent compromise
|
|
|
|
# is to use Z to convey the meaning RFC3339 gave to -00:00. So the use
|
|
|
|
# of -00:00 as offset suffix should be avoided (and, by extension,
|
|
|
|
# likewise for UTC-00:00 as a zone ID), but this suffix (and ID)
|
|
|
|
# should be recognized when consuming data generated by other sources,
|
|
|
|
# for backwards compatibility.
|
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
class ByteArrayData:
|
|
|
|
def __init__(self):
|
|
|
|
self.data = []
|
|
|
|
self.hash = {}
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
def append(self, s):
|
|
|
|
s = s + '\0'
|
|
|
|
if s in self.hash:
|
|
|
|
return self.hash[s]
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
lst = unicode2hex(s)
|
|
|
|
index = len(self.data)
|
|
|
|
if index > 0xffff:
|
2021-07-06 14:22:07 +00:00
|
|
|
raise Error(f'Index ({index}) outside the uint16 range !')
|
2020-02-19 15:10:45 +00:00
|
|
|
self.hash[s] = index
|
|
|
|
self.data += lst
|
|
|
|
return index
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
def write(self, out, name):
|
2022-05-24 04:32:02 +00:00
|
|
|
out(f'\nstatic constexpr char {name}[] = {{\n')
|
2023-07-28 07:58:21 +00:00
|
|
|
out(wrap_list(self.data, 16)) # 16 == 100 // len('0xhh, ')
|
|
|
|
# Will over-spill 100-col if some 4-digit hex show up, but none do (yet).
|
2020-02-19 15:10:45 +00:00
|
|
|
out('\n};\n')
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
class ZoneIdWriter (SourceFileEditor):
|
|
|
|
def write(self, version, defaults, windowsIds):
|
|
|
|
self.__writeWarning(version)
|
|
|
|
windows, iana = self.__writeTables(self.writer.write, defaults, windowsIds)
|
|
|
|
windows.write(self.writer.write, 'windowsIdData')
|
|
|
|
iana.write(self.writer.write, 'ianaIdData')
|
2015-03-23 09:58:37 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
def __writeWarning(self, version):
|
2021-07-06 14:22:07 +00:00
|
|
|
self.writer.write(f"""
|
2020-02-19 15:10:45 +00:00
|
|
|
/*
|
2021-07-06 14:22:07 +00:00
|
|
|
This part of the file was generated on {datetime.date.today()} from the
|
|
|
|
Common Locale Data Repository v{version} file supplemental/windowsZones.xml
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
http://www.unicode.org/cldr/
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
Do not edit this code: run cldr2qtimezone.py on updated (or
|
|
|
|
edited) CLDR data; see qtbase/util/locale_database/.
|
|
|
|
*/
|
2013-01-27 13:52:56 +00:00
|
|
|
|
2021-07-06 14:22:07 +00:00
|
|
|
""")
|
2020-02-19 15:10:45 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def __writeTables(out, defaults, windowsIds):
|
|
|
|
windowsIdData, ianaIdData = ByteArrayData(), ByteArrayData()
|
|
|
|
|
|
|
|
# Write Windows/IANA table
|
2021-05-04 11:20:32 +00:00
|
|
|
out('// Windows ID Key, Territory Enum, IANA ID Index\n')
|
2022-05-24 04:32:02 +00:00
|
|
|
out('static constexpr QZoneData zoneDataTable[] = {\n')
|
2020-02-19 15:10:45 +00:00
|
|
|
for index, data in sorted(windowsIds.items()):
|
|
|
|
out(' {{ {:6d},{:6d},{:6d} }}, // {} / {}\n'.format(
|
2021-05-04 11:20:32 +00:00
|
|
|
data['windowsKey'], data['territoryId'],
|
2020-02-19 15:10:45 +00:00
|
|
|
ianaIdData.append(data['ianaList']),
|
2021-05-04 11:20:32 +00:00
|
|
|
data['windowsId'], data['territory']))
|
2020-02-19 15:10:45 +00:00
|
|
|
out('};\n\n')
|
|
|
|
|
|
|
|
# Write Windows ID key table
|
|
|
|
out('// Windows ID Key, Windows ID Index, IANA ID Index, UTC Offset\n')
|
2022-05-24 04:32:02 +00:00
|
|
|
out('static constexpr QWindowsData windowsDataTable[] = {\n')
|
2020-02-19 15:10:45 +00:00
|
|
|
for index, pair in enumerate(windowsIdList, 1):
|
|
|
|
out(' {{ {:6d},{:6d},{:6d},{:6d} }}, // {}\n'.format(
|
|
|
|
index,
|
|
|
|
windowsIdData.append(pair[0]),
|
|
|
|
ianaIdData.append(defaults[index]),
|
|
|
|
pair[1], pair[0]))
|
|
|
|
out('};\n\n')
|
|
|
|
|
Convert UTC offset table look-ups to binary chop
The table was almost sorted by offset - its UTC entry, with offset 0,
was at the front rather than first among the offset 0 entries. The
lookups in it were being done as if the IDs were in space-joined lists
(as for the IANA IDs in the Windows table), splitting on space,
despite the fact that it had separate entries for different IDs at the
same offset (this only arose for offset 0). So actually massage the
input table in python to combine IDs with the same offset using space,
placing UTC first among the offset 0 entries, and ensure the C++ table
is sorted. Regenerated the CLDR data tables using the updated script.
In the process, fix an off-by-one error in the iteration over
space-joined IDs, where the search only advanced to the space, rather
than to just after it. That wasn't a problem before, but now would be.
Change-Id: Ib49c27bac269b557166fa10738c3e396d58456c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-30 12:35:48 +00:00
|
|
|
offsetMap = {}
|
|
|
|
for pair in utcIdList:
|
|
|
|
offsetMap[pair[1]] = offsetMap.get(pair[1], ()) + (pair[0],)
|
2020-02-19 15:10:45 +00:00
|
|
|
# Write UTC ID key table
|
|
|
|
out('// IANA ID Index, UTC Offset\n')
|
2022-05-24 04:32:02 +00:00
|
|
|
out('static constexpr QUtcData utcDataTable[] = {\n')
|
Convert UTC offset table look-ups to binary chop
The table was almost sorted by offset - its UTC entry, with offset 0,
was at the front rather than first among the offset 0 entries. The
lookups in it were being done as if the IDs were in space-joined lists
(as for the IANA IDs in the Windows table), splitting on space,
despite the fact that it had separate entries for different IDs at the
same offset (this only arose for offset 0). So actually massage the
input table in python to combine IDs with the same offset using space,
placing UTC first among the offset 0 entries, and ensure the C++ table
is sorted. Regenerated the CLDR data tables using the updated script.
In the process, fix an off-by-one error in the iteration over
space-joined IDs, where the search only advanced to the space, rather
than to just after it. That wasn't a problem before, but now would be.
Change-Id: Ib49c27bac269b557166fa10738c3e396d58456c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-30 12:35:48 +00:00
|
|
|
for offset in sorted(offsetMap.keys()): # Sort so C++ can binary-chop.
|
|
|
|
names = offsetMap[offset];
|
2020-02-19 15:10:45 +00:00
|
|
|
out(' {{ {:6d},{:6d} }}, // {}\n'.format(
|
Convert UTC offset table look-ups to binary chop
The table was almost sorted by offset - its UTC entry, with offset 0,
was at the front rather than first among the offset 0 entries. The
lookups in it were being done as if the IDs were in space-joined lists
(as for the IANA IDs in the Windows table), splitting on space,
despite the fact that it had separate entries for different IDs at the
same offset (this only arose for offset 0). So actually massage the
input table in python to combine IDs with the same offset using space,
placing UTC first among the offset 0 entries, and ensure the C++ table
is sorted. Regenerated the CLDR data tables using the updated script.
In the process, fix an off-by-one error in the iteration over
space-joined IDs, where the search only advanced to the space, rather
than to just after it. That wasn't a problem before, but now would be.
Change-Id: Ib49c27bac269b557166fa10738c3e396d58456c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-30 12:35:48 +00:00
|
|
|
ianaIdData.append(' '.join(names)), offset, names[0]))
|
2020-02-19 15:10:45 +00:00
|
|
|
out('};\n')
|
|
|
|
|
|
|
|
return windowsIdData, ianaIdData
|
|
|
|
|
|
|
|
|
2021-07-07 10:41:10 +00:00
|
|
|
def main(out, err):
|
2020-02-19 15:10:45 +00:00
|
|
|
"""Parses CLDR's data and updates Qt's representation of it.
|
|
|
|
|
2021-07-07 10:41:10 +00:00
|
|
|
Takes sys.stdout, sys.stderr (or equivalents) as
|
2020-02-27 09:56:36 +00:00
|
|
|
arguments. Expects two command-line options: the root of the
|
|
|
|
unpacked CLDR data-file tree and the root of the qtbase module's
|
|
|
|
checkout. Updates QTimeZone's private data about Windows time-zone
|
|
|
|
IDs."""
|
2021-07-07 10:41:10 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Update Qt's CLDR-derived timezone data.")
|
|
|
|
parser.add_argument('cldr_path', help='path to the root of the CLDR tree')
|
2022-10-17 08:58:31 +00:00
|
|
|
parser.add_argument('qtbase_path',
|
|
|
|
help='path to the root of the qtbase source tree',
|
|
|
|
nargs='?', default=qtbase_root)
|
2021-07-07 10:41:10 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
2020-02-19 15:10:45 +00:00
|
|
|
|
2021-07-09 13:34:40 +00:00
|
|
|
cldrPath = Path(args.cldr_path)
|
|
|
|
qtPath = Path(args.qtbase_path)
|
2020-02-19 15:10:45 +00:00
|
|
|
|
2021-07-09 13:34:40 +00:00
|
|
|
if not qtPath.is_dir():
|
2021-07-07 10:41:10 +00:00
|
|
|
parser.error(f"No such Qt directory: {qtPath}")
|
|
|
|
|
2021-07-09 13:34:40 +00:00
|
|
|
if not cldrPath.is_dir():
|
2021-07-07 10:41:10 +00:00
|
|
|
parser.error(f"No such CLDR directory: {cldrPath}")
|
2020-02-19 15:10:45 +00:00
|
|
|
|
2021-07-09 13:34:40 +00:00
|
|
|
dataFilePath = qtPath.joinpath('src/corelib/time/qtimezoneprivate_data_p.h')
|
|
|
|
|
|
|
|
if not dataFilePath.is_file():
|
2021-07-07 10:41:10 +00:00
|
|
|
parser.error(f'No such file: {dataFilePath}')
|
2020-02-19 15:10:45 +00:00
|
|
|
|
2020-02-27 09:56:36 +00:00
|
|
|
try:
|
|
|
|
version, defaults, winIds = CldrAccess(cldrPath).readWindowsTimeZones(
|
|
|
|
dict((name, ind) for ind, name in enumerate((x[0] for x in windowsIdList), 1)))
|
|
|
|
except IOError as e:
|
2021-07-07 10:41:10 +00:00
|
|
|
parser.error(
|
|
|
|
f'Failed to open common/supplemental/windowsZones.xml: {e}')
|
2020-02-19 15:10:45 +00:00
|
|
|
return 1
|
2020-02-27 09:56:36 +00:00
|
|
|
except Error as e:
|
|
|
|
err.write('\n'.join(textwrap.wrap(
|
2021-07-06 14:22:07 +00:00
|
|
|
f'Failed to read windowsZones.xml: {e}',
|
2020-02-27 09:56:36 +00:00
|
|
|
subsequent_indent=' ', width=80)) + '\n')
|
2020-02-19 15:10:45 +00:00
|
|
|
return 1
|
|
|
|
|
|
|
|
out.write('Input file parsed, now writing data\n')
|
|
|
|
|
|
|
|
try:
|
2021-07-12 12:11:39 +00:00
|
|
|
with ZoneIdWriter(dataFilePath, qtPath) as writer:
|
|
|
|
writer.write(version, defaults, winIds)
|
|
|
|
except Exception as e:
|
|
|
|
err.write(f'\nError while updating timezone data: {e}\n')
|
2020-02-19 15:10:45 +00:00
|
|
|
return 1
|
|
|
|
|
2021-07-06 14:22:07 +00:00
|
|
|
out.write(f'Data generation completed, please check the new file at {dataFilePath}\n')
|
2020-02-19 15:10:45 +00:00
|
|
|
return 0
|
2017-05-12 09:59:18 +00:00
|
|
|
|
2020-02-19 15:10:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
2021-07-07 10:41:10 +00:00
|
|
|
sys.exit(main(sys.stdout, sys.stderr))
|