]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Use `day_periods` for `get_period_names`
authorAarni Koskela <akx@iki.fi>
Sun, 14 Feb 2016 17:37:40 +0000 (19:37 +0200)
committerAarni Koskela <akx@iki.fi>
Sat, 5 Mar 2016 19:21:52 +0000 (21:21 +0200)
babel/core.py
babel/dates.py

index 1c6c98a2f8384adc96ede59a671085a49fae7231..f6bc25f14e25e5a298b8214dcebd937e808101d5 100644 (file)
@@ -619,6 +619,14 @@ class Locale(object):
         except KeyError:
             return {}
 
+    @property
+    def day_periods(self):
+        """Locale display names for various day periods (not necessarily only AM/PM).
+
+        These are not meant to be used without the relevant `day_period_rules`.
+        """
+        return self._data['day_periods']
+
     @property
     def days(self):
         """Locale display names for weekdays.
index 0ba2a2f5ef881b85451b49b5f3a4acb4b4916a6c..65c59735630100dd39ebdad7c7c5c57a15745b1e 100644 (file)
@@ -247,15 +247,17 @@ class TimezoneTransition(object):
         )
 
 
-def get_period_names(locale=LC_TIME):
+def get_period_names(width='wide', context='stand-alone', locale=LC_TIME):
     """Return the names for day periods (AM/PM) used by the locale.
 
     >>> get_period_names(locale='en_US')['am']
     u'AM'
 
+    :param width: the width to use, one of "abbreviated", "narrow", or "wide"
+    :param context: the context, either "format" or "stand-alone"
     :param locale: the `Locale` object, or a locale string
     """
-    return Locale.parse(locale).periods
+    return Locale.parse(locale).day_periods[context][width]
 
 
 def get_day_names(width='wide', context='format', locale=LC_TIME):