def get_locale_timezones(locale): """Function returning preferred timezones for the given locale. :param locale: locale string :type locale: str :return: list of preferred timezones :rtype: list of strings :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode) """ raise_on_invalid_locale(locale) return langtable.list_timezones(languageId=locale)
def get_preferred_timezone(territory): """ Get the preferred timezone for a given territory. Note that this function simply returns the first timezone in the list of timezones for a given territory. :param territory: territory to get preferred timezone for :type territory: str :return: preferred timezone for the given territory or None if no found :rtype: str or None """ timezones = langtable.list_timezones(territoryId=territory) if not timezones: return None return timezones[0]
def get_locale_timezones(locale): """ Function returning preferred timezones for the given locale. :param locale: locale string (see LANGCODE_RE) :type locale: str :return: list of preferred timezones :rtype: list of strings :raise InvalidLocaleSpec: if an invalid locale is given (see LANGCODE_RE) """ parts = parse_langcode(locale) if "language" not in parts: raise InvalidLocaleSpec("'%s' is not a valid locale" % locale) return langtable.list_timezones(languageId=parts["language"], territoryId=parts.get("territory", ""), scriptId=parts.get("script", ""))