]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fix day periods to work with CLDR 29 data 405/head
authorAarni Koskela <akx@iki.fi>
Tue, 17 May 2016 06:21:46 +0000 (09:21 +0300)
committerAarni Koskela <akx@iki.fi>
Wed, 22 Jun 2016 07:05:57 +0000 (10:05 +0300)
babel/dates.py
scripts/import_cldr.py

index 4a0bbd3e001a062ddc9e3be6bd3b4bedc2c70776..523e4562de5087f21a0ad498542f0ef9fc13c113 100644 (file)
@@ -1080,12 +1080,16 @@ def get_period_id(time, tzinfo=None, type=None, locale=LC_TIME):
     locale = Locale.parse(locale)
 
     # The LDML rules state that the rules may not overlap, so iterating in arbitrary
-    # order should be alright.
-    for rule_id, rules in locale.day_period_rules.get(type, {}).items():
+    # order should be alright, though `at` periods should be preferred.
+    rulesets = locale.day_period_rules.get(type, {}).items()
+
+    for rule_id, rules in rulesets:
         for rule in rules:
             if "at" in rule and rule["at"] == seconds_past_midnight:
                 return rule_id
 
+    for rule_id, rules in rulesets:
+        for rule in rules:
             start_ok = end_ok = False
 
             if "from" in rule and seconds_past_midnight >= rule["from"]:
@@ -1096,8 +1100,8 @@ def get_period_id(time, tzinfo=None, type=None, locale=LC_TIME):
                 end_ok = True
             if "before" in rule and seconds_past_midnight < rule["before"]:
                 end_ok = True
-            if "after" in rule and seconds_past_midnight > rule["after"]:
-                start_ok = True
+            if "after" in rule:
+                raise NotImplementedError("'after' is deprecated as of CLDR 29.")
 
             if start_ok and end_ok:
                 return rule_id
index 8de704360b097cecb833cdc5f9a81e6fc45b654c..b8041193f8ec3940ea0231c9438b7e75100b2cc5 100755 (executable)
@@ -845,6 +845,8 @@ def parse_day_period_rules(tree):
             locales = rules.attrib["locales"].split()
             for rule in rules.findall("dayPeriodRule"):
                 type = rule.attrib["type"]
+                if type in ("am", "pm"):  # These fixed periods are handled separately by `get_period_id`
+                    continue
                 rule = _compact_dict(dict(
                     (key, _time_to_seconds_past_midnight(rule.attrib.get(key)))
                     for key in ("after", "at", "before", "from", "to")