Ejemplo n.º 1
0
def get_month_name(month_no, locale):
    if sys.version_info[0] == 3:  # Python 3
        with calendar.different_locale((locale, "UTF-8")):
            s = calendar.month_name[month_no]
    else:  # Python 2
        with calendar.TimeEncoding((locale, "UTF-8")):
            s = calendar.month_name[month_no]
    return s
Ejemplo n.º 2
0
    def test_type_of_month_name(self):
        """validate assumption calendar month name is of type str

        Yes, both in windows and linuxTravis, py 26, 27, 33
        """
        import calendar
        if sys.version_info[0] == 3:  # Python 3
            with calendar.different_locale(loc_11):
                s = calendar.month_name[1]
        else:  # Python 2
            with calendar.TimeEncoding(loc_11):
                s = calendar.month_name[1]
        self.assertTrue(type(s) == str)
Ejemplo n.º 3
0
 def get_month_name(self, month_no, lang):
     """returns localized month name in an unicode string"""
     if sys.version_info[0] == 3:  # Python 3
         with calendar.different_locale(self.locales[lang]):
             s = calendar.month_name[month_no]
         # for py3 s is unicode
     else:  # Python 2
         with calendar.TimeEncoding(self.locales[lang]):
             s = calendar.month_name[month_no]
         s = s.decode(self.encodings[lang])
     # paranoid about calendar ending in the wrong locale (windows)
     self.set_locale(self.current_lang)
     return s
Ejemplo n.º 4
0
def day_of_week_str(day_of_week, lang):
    with calendar.TimeEncoding(lang):
        return calendar.day_abbr[day_of_week].title()