def build_longlist_timezone_pairs(self, country_code, sort=True):
     if 'LANG' not in os.environ:
         return []  # ?!
     locale = os.environ['LANG'].rsplit('.', 1)[0]
     tz_format = icu.SimpleDateFormat('VVVV', icu.Locale(locale))
     now = time.time() * 1000
     rv = []
     try:
         locs = self.tzdb.cc_to_locs[country_code]  # BV failed?
     except Exception:
         # Some countries in tzsetup don't exist in zone.tab...
         # Specifically BV (Bouvet Island) and
         # HM (Heard and McDonald Islands).  Both are uninhabited.
         locs = []
     for location in locs:
         timezone = icu.TimeZone.createTimeZone(location.zone)
         if timezone.getID() == 'Etc/Unknown':
             translated = None
         else:
             tz_format.setTimeZone(timezone)
             translated = tz_format.format(now)
         # Check if icu had a valid translation for this timezone.  If it
         # doesn't, the returned string will look like GMT+0002 or somesuch.
         # Sometimes the GMT is translated (like in Chinese), so we check
         # for the number part.  icu does not indicate a 'translation
         # failure' like this in any way...
         if (translated is None or
                 re.search('.*[-+][0-9][0-9]:?[0-9][0-9]$', translated)):
             # Wasn't something that icu understood...
             name = self.get_fallback_translation_for_tz(
                 country_code, location.zone)
             rv.append((name, location.zone))
         else:
             rv.append((translated, location.zone))
     if sort:
         rv.sort(key=self.collation_key)
     return rv
Beispiel #2
0
def parse_to_ts(dt):
    df = icu.SimpleDateFormat('dd.MM.yyyy, HH:mm', icu.Locale('de_DE'))
    ts = _try_parse(dt, df)
    return ts
Beispiel #3
0
 def parse_date(self, s_date, fmt='dd MMMM yyyy г., hh:mm'):
     f = icu.SimpleDateFormat(fmt, icu.Locale('ru'))
     return datetime.fromtimestamp(int(f.parse(s_date)))