From patchwork Wed Sep 23 09:38:12 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike FABIAN X-Patchwork-Id: 144479 X-Patchwork-Delegate: arjun.is@lostca.se Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63FD64BA9034 for ; Wed, 23 Sep 2026 09:39:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63FD64BA9034 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y6iiRBou X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id C305A4BA23F3 for ; Wed, 23 Sep 2026 09:38:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C305A4BA23F3 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C305A4BA23F3 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790156322; cv=none; b=F78ZBBCEAkSr4S0PDMav410qHx+/bRMc+8zPdFKW6Wu+tpeA4BlnkA/0N9dOlZqhTpUPDRR6g2nsVa+ht22c3mAIXFwMsWA2pXemuNIW4RZX+DzOWO+YqwJlGpha2/QaFu9ESclvTllk33igYZoBV+G7cKqwm6HswOgr9cUQRq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790156322; c=relaxed/simple; bh=QuJ92SptFVAchU51zd5mErjMoG0zmVUJUicf48dO4QI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ErqNyN9qkA21wMxIjymSzGLj4YqSQtDxazFMz4ejPGWoRics2Yi73bqIJ+N+s7omchrscxwJkov2dOC1DAjlAIIX7+GEAGE0KIOn0V6AnyWh8Wet+jAxp7iG0gSSZFVJpwbOT2wDXQzuuwYztB/jJ0sGsIxWnbqOup/xHUueSbo= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y6iiRBou DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C305A4BA23F3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1790156322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jXtcBC0U3hFWQl0lN/zfYXckk/d9HdqXR85b+l0C7ww=; b=Y6iiRBouv2/Al4R111q165yfPGly2+gF6iMyGsE2rsMV4YDwIFuHv8ybZ6TIWD/BjGe6vG xUfmXvrwb61SdKkGO1hQXr2KWTou/d/g1ZxrLr2MuZLGy5wmUWd9ZoLOfqCDdv7CTP1FqF LexUNdxeAK0hJD/SaQEc2mh4cJKwj08= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-F_aWNagOOBez9TQKIZfyIQ-1; Wed, 23 Sep 2026 05:38:39 -0400 X-MC-Unique: F_aWNagOOBez9TQKIZfyIQ-1 X-Mimecast-MFC-AGG-ID: F_aWNagOOBez9TQKIZfyIQ_1790156318 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-49cf9df1eadso5748345e9.3 for ; Wed, 23 Sep 2026 02:38:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790156318; x=1790761118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=jXtcBC0U3hFWQl0lN/zfYXckk/d9HdqXR85b+l0C7ww=; b=Ckn4ggq3OiqJS2fnPVOw8vtNMljNg5rwETG/M4ZQ8QEv3vu/dHkLd6Zzd+FjKzfYg7 U1E24ruZgOWywxcGMM5ZWxb5PE/SoGS1L48kkjk+7a0V5lV+jqcnRB8enY3q35BeNBON r3dPyFh+nqsQTmo0q8T9xBJHzFYaED1M3ZVnXDWpZrZEVDQu/z5D1VmM7fKuGz0NZ+P0 3J0LfD3KOxK6iC7dA9ZX8Xmowu5lf3UOlmYJmXnHeypc3q9xcclJc8lU6C6zJ/Gv+eQd rgTRk9V2kB30GybMWUW/AjGhjkR/x2EVVqalPvpQ9MbZ3oGmgH2xsn7Ydfy8MqzAlUgq QhyA== X-Gm-Message-State: AFuF++nm6Bkl2jlcRuP0P2xjW88+ZgiX/WuiyyIkbzOzmBdczxyuoE+8 xMtFOTJS9ejsYrmJndr7u+yaO+HQFTa5UQO/JKZApGs4zOjkeHZZSivh6oaDzGlq3DAMJ9UMhgC V7SGFqx3uWUp5PMq2I62JQHJjaFyWpcJ2MAplzABnqGi/IPAW2NeLnNdEtfpEV5nlNtC2 X-Gm-Gg: AYBFou1Y0gpoN5/kRh50/hfO/jHoCPOEv+49JdPacqu8ame+sI2Ce/6fMYa5H+OssJv WI3p5f3VL+uiXxdgecTw/ZS+ygFUfV5rfNS5Eqy4dm1MNrVsbma5B3hFqo0/q0VUbNuj5h+/1K5 g4rOenzQlKDpqUtNx8ZwXkj7Z9+Q/3B78YNBlCY+6vdnSYg5hKU2n9xrfqNEGGaANVi4m45NFSq w9MMZush/XLkteZRYZQhwYdNGwZZa/L3HIEAGK0sEUZ1MtnWRkc8+EKvIQGCxHO86fyHbKnmCn5 SaqTN0aisG30+jo26yE06wKv8sVCr3WPaW8hb5e9ciPHAxzPndqIFw8A9nkwJG3v+QkYLud/EW7 6miVk5KzosDIKpGgj34HMSvolP6rm5bbob3NGp3IUVV3JnYGJqWw= X-Received: by 2002:a05:600c:1908:b0:49e:8184:f63b with SMTP id 5b1f17b1804b1-49fdf12a2c6mr22716215e9.16.1790156318232; Wed, 23 Sep 2026 02:38:38 -0700 (PDT) X-Received: by 2002:a05:600c:1908:b0:49e:8184:f63b with SMTP id 5b1f17b1804b1-49fdf12a2c6mr22715805e9.16.1790156317698; Wed, 23 Sep 2026 02:38:37 -0700 (PDT) Received: from hathi.site (p200300efa7025800bb3cd26a7e07244d.dip0.t-ipconnect.de. [2003:ef:a702:5800:bb3c:d26a:7e07:244d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fde1d978fsm57160615e9.9.2026.09.23.02.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 02:38:36 -0700 (PDT) Received: by hathi.site (Postfix, from userid 10030) id F400A80944; Wed, 23 Sep 2026 11:38:35 +0200 (CEST) From: Mike FABIAN To: libc-alpha@sourceware.org Cc: Mike FABIAN Subject: [PATCH 2/2] Add a script to check whether week, first_weekday, first_workday in glibc agrees with CLDR. Date: Wed, 23 Sep 2026 11:38:12 +0200 Message-ID: <20260923093817.2901603-2-mfabian@redhat.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260923093817.2901603-1-mfabian@redhat.com> References: <20260923093817.2901603-1-mfabian@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Gm3zF_0iZNNKiTaSwD9D72UPD8b0eZuWna2Y3N855so_1790156318 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, POISEN_SPAM_PILL, POISEN_SPAM_PILL_1, POISEN_SPAM_PILL_3, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_PBL, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org See: https://github.com/unicode-org/cldr/blob/main/common/supplemental/supplementalData.xml Run of check script: $ ./cldr_week_data_check.py ../../../cldr/common/supplemental/supplementalData.xml '../locales/*_[A-Z][A-Z]' $ If the the data in CLDR and glibc agrees, this script prints nothing. If there are differences it prints warnings like for example: $ ./cldr_week_data_check.py /local/mfabian/src/cldr/common/supplemental/supplementalData.xml '../locales/*_[A-Z][A-Z]' WARNING ru_UA: LC_TIME copied from ru_RU but expected CLDR minDays differs. $ ./cldr_week_data_check.py /local/mfabian/src/cldr/common/supplemental/supplementalData.xml '../locales/*_[A-Z][A-Z]' WARNING: ru_UA: week MINWEEKLEN = 4, CLDR minDays = 1 $ --- .../unicode-gen/cldr_week_data_check.py | 258 ++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100755 localedata/unicode-gen/cldr_week_data_check.py diff --git a/localedata/unicode-gen/cldr_week_data_check.py b/localedata/unicode-gen/cldr_week_data_check.py new file mode 100755 index 0000000000..5dada02603 --- /dev/null +++ b/localedata/unicode-gen/cldr_week_data_check.py @@ -0,0 +1,258 @@ +#!/usr/bin/python3 +# Copyright (C) 2026 Free Software Foundation, Inc. +# Copyright The GNU Toolchain Authors. +# This file is part of the GNU C Library. +# +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# . +''' +This script compares the week data in cldr/common/supplemental/supplementalData.xml +with the week data in the glibc locales. +''' +import glob +import re +import sys +import xml.etree.ElementTree as ET +from pathlib import Path + +# CLDR names -> glibc LC_TIME day numbers. +# glibc's day list is: +# 1 = Sunday +# 2 = Monday +# 3 = Tuesday +# 4 = Wednesday +# 5 = Thursday +# 6 = Friday +# 7 = Saturday +DAY_NUMBERS = { + 'sun': 1, + 'mon': 2, + 'tue': 3, + 'wed': 4, + 'thu': 5, + 'fri': 6, + 'sat': 7, +} + +def parse_territories(value: str) -> list[str]: + '''Split a CLDR territories attribute into territory codes.''' + return value.split() + +def parse_week_data(xml_file: Path) -> tuple[ + dict[str, int], + dict[str, int], + dict[str, int], + dict[str, int], +]: + '''Parse CLDR supplementalData.xml weekData.''' + tree = ET.parse(xml_file) + root = tree.getroot() + week_data = root.find('.//weekData') + if week_data is None: + raise ValueError('Could not find ') + min_days: dict[str, int] = {} + first_day: dict[str, int] = {} + weekend_start: dict[str, int] = {} + weekend_end: dict[str, int] = {} + for element in week_data: + # Ignore entries such as: + # + # + # + # We want the normal/default CLDR data. + if 'alt' in element.attrib: + continue + territories = parse_territories(element.get('territories', '')) + if element.tag == 'minDays': + count = int(element.attrib['count']) + for territory in territories: + min_days[territory] = count + elif element.tag in {'firstDay', 'weekendStart', 'weekendEnd'}: + day = element.attrib['day'] + try: + day_number = DAY_NUMBERS[day] + except KeyError as exc: + raise ValueError(f'Unknown CLDR day: {day!r}') from exc + target = { + 'firstDay': first_day, + 'weekendStart': weekend_start, + 'weekendEnd': weekend_end, + }[element.tag] + + for territory in territories: + target[territory] = day_number + else: + # Ignore other weekData elements if CLDR adds any in future. + continue + return min_days, first_day, weekend_start, weekend_end + +def extract_lc_time(text: str) -> str | None: + '''Return the contents of the LC_TIME section.''' + match = re.search(r'(?ms)^LC_TIME\b(.*?)(?=^END LC_TIME\b)', text) + if match is None: + return None + return match.group(1) + +def parse_lc_time(lc_time: str) -> tuple[str | None, int | None, int | None, int | None]: + ''' + Parse copy, week, first_weekday, and first_workday + from an LC_TIME section. + + Returns: + (copy_locale, min_days, first_weekday, first_workday) + ''' + copy_match = re.search(r'(?m)^\s*copy\s+"([^"]+)"', lc_time) + copy_locale = copy_match.group(1) if copy_match else None + week_match = re.search(r"(?m)^\s*week\s+([^#\n]+)", lc_time) + min_days = None + if week_match: + fields = week_match.group(1).strip().split(";") + if len(fields) != 3: + print('WARNING: malformed week line:', week_match.group(0).strip()) + else: + try: + min_days = int(fields[2]) + except ValueError: + print('WARNING: invalid MINWEEKLEN in:', week_match.group(0).strip()) + first_weekday_match = re.search(r'(?m)^\s*first_weekday\s+(\d+)', lc_time) + first_weekday = ( + int(first_weekday_match.group(1)) + if first_weekday_match + else None + ) + first_workday_match = re.search(r'(?m)^\s*first_workday\s+(\d+)', lc_time) + first_workday = ( + int(first_workday_match.group(1)) + if first_workday_match + else None + ) + return (copy_locale, min_days, first_weekday, first_workday) + +def expected_value( + values: dict[str, int], + territory: str, +) -> int: + '''Get a CLDR value, using territory 001 as the default.''' + return values.get(territory, values['001']) + +def expected_first_workday( + weekend_end: dict[str, int], + territory: str, +) -> int: + ''' + The first workday is the day after CLDR weekendEnd. + + With glibc day numbers: + Sunday = 1 + ... + Saturday = 7 + ''' + end_day = expected_value(weekend_end, territory) + return end_day % 7 + 1 + +def check_locale( + filename: str, + *, + min_days: dict[str, int], + first_day: dict[str, int], + weekend_end: dict[str, int], +) -> None: + '''Check one glibc locale file.''' + path = Path(filename) + # For *_CC locale names, the territory is the final two characters. + # Examples: + # pt_PT -> PT + # chr_US -> US + # ber_MA -> MA + territory = path.name[-2:] + text = path.read_text(encoding='utf-8') + lc_time = extract_lc_time(text) + if lc_time is None: + print(f'WARNING: {path.name}: no LC_TIME section') + return + ( + copy_locale, + locale_min_days, + locale_first_weekday, + locale_first_workday, + ) = parse_lc_time(lc_time) + expected_min_days = expected_value(min_days, territory) + expected_first_weekday = expected_value(first_day, territory) + expected_workday = expected_first_workday(weekend_end, territory) + if copy_locale is not None: + copy_territory = copy_locale[-2:] + if expected_min_days != expected_value(min_days, copy_territory): + print(f'WARNING {path.name}: LC_TIME copied from {copy_locale} but expected CLDR minDays differs.') + if expected_first_weekday != expected_value(first_day, copy_territory): + print(f'WARNING {path.name}: LC_TIME copied from {copy_locale} but expected CLDR firstDay differs.') + if expected_workday != expected_first_workday(weekend_end, copy_territory): + print(f'WARNING {path.name}: LC_TIME copied from {copy_locale} but expected CLDR weekendEnd differs.') + return + # Check that all three values exist. + missing = [] + if locale_min_days is None: + missing.append('week') + if locale_first_weekday is None: + missing.append('first_weekday') + if locale_first_workday is None: + missing.append('first_workday') + if missing: + print(f'WARNING: {path.name}: missing ' + ', '.join(missing)) + return + if locale_min_days != expected_min_days: + print(f'WARNING: {path.name}: ' + f'week MINWEEKLEN = {locale_min_days}, ' + f'CLDR minDays = {expected_min_days}') + if locale_first_weekday != expected_first_weekday: + print(f'WARNING: {path.name}: ' + f'first_weekday = {locale_first_weekday}, ' + f'CLDR firstDay = {expected_first_weekday}') + if locale_first_workday != expected_workday: + print(f'WARNING: {path.name}: ' + f'first_workday = {locale_first_workday}, ' + f'CLDR weekendEnd implies {expected_workday}') + +def main() -> None: + if len(sys.argv) != 3: + print(f'usage: {sys.argv[0]} ' + "supplementalData.xml 'locales/*_[A-Z][A-Z]'", + file=sys.stderr) + sys.exit(2) + xml_file = Path(sys.argv[1]) + locale_pattern = sys.argv[2] + ( + min_days, + first_day, + weekend_start, + weekend_end, + ) = parse_week_data(xml_file) + # Make sure CLDR has its 001 defaults. + for name, values in ( + ('min_days', min_days), + ('first_day', first_day), + ('weekend_start', weekend_start), + ('weekend_end', weekend_end), + ): + if '001' not in values: + raise ValueError(f'{name} has no CLDR 001 default') + for filename in sorted(glob.glob(locale_pattern)): + check_locale( + filename, + min_days=min_days, + first_day=first_day, + weekend_end=weekend_end, + ) + +if __name__ == '__main__': + main()