From a1a0a2310bbc7b9c926e972076bffbd626d8081c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 14 Feb 2016 19:37:40 +0200 Subject: [PATCH] Use `day_periods` for `get_period_names` --- babel/core.py | 8 ++++++++ babel/dates.py | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/babel/core.py b/babel/core.py index 1c6c98a2..f6bc25f1 100644 --- a/babel/core.py +++ b/babel/core.py @@ -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. diff --git a/babel/dates.py b/babel/dates.py index 0ba2a2f5..65c59735 100644 --- a/babel/dates.py +++ b/babel/dates.py @@ -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): -- 2.47.2