Add Fallback to display date without timezone info (for windows historical dates)

This commit is contained in:
Prinz23 2016-08-15 01:16:35 +02:00 committed by JackDandy
parent b58ef9267c
commit c789c8a14c

View file

@ -104,6 +104,14 @@ class static_or_instance(object):
class sbdatetime(datetime.datetime): class sbdatetime(datetime.datetime):
has_locale = True has_locale = True
@static_or_instance
def is_locale_eng(self):
return (sbdatetime.sbdatetime.sbfdate(datetime.datetime.now(), '%A').lower() in [
'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'] and
sbdatetime.sbdatetime.sbfdate(datetime.datetime.now(), '%B').lower() in [
'january', 'february', 'march', 'april', 'may', 'june',
'july', 'august', 'september', 'october', 'november', 'december'])
@static_or_instance @static_or_instance
def convert_to_setting(self, dt=None): def convert_to_setting(self, dt=None):
obj = (dt, self)[self is not None] obj = (dt, self)[self is not None]
@ -121,7 +129,7 @@ class sbdatetime(datetime.datetime):
try: try:
if None is use_has_locale or use_has_locale: if None is use_has_locale or use_has_locale:
locale.setlocale(locale.LC_TIME, locale_str) locale.setlocale(locale.LC_TIME, locale_str)
except: except locale.Error:
if None is not use_has_locale: if None is not use_has_locale:
sbdatetime.has_locale = False sbdatetime.has_locale = False
pass pass
@ -133,14 +141,18 @@ class sbdatetime(datetime.datetime):
sbdatetime.setlocale(setlocale=setlocale, use_has_locale=sbdatetime.has_locale, locale_str='us_US') sbdatetime.setlocale(setlocale=setlocale, use_has_locale=sbdatetime.has_locale, locale_str='us_US')
strt = '' strt = ''
try:
obj = (dt, self)[self is not None] obj = (dt, self)[self is not None]
if None is not obj: if None is not obj:
tmpl = (((sickbeard.TIME_PRESET, sickbeard.TIME_PRESET_W_SECONDS)[show_seconds]), tmpl = (((sickbeard.TIME_PRESET, sickbeard.TIME_PRESET_W_SECONDS)[show_seconds]),
t_preset)[None is not t_preset] t_preset)[None is not t_preset]
tmpl = (tmpl.replace(':%S', ''), tmpl)[show_seconds] tmpl = (tmpl.replace(':%S', ''), tmpl)[show_seconds]
strt = obj.strftime(tmpl.replace('%P', '%p')) pm_token = tmpl.replace('%P', '%p')
try:
strt = obj.strftime(pm_token)
except ValueError:
strt = obj.replace(tzinfo=None).strftime(pm_token)
if sickbeard.TRIM_ZERO: if sickbeard.TRIM_ZERO:
strt = re.sub(r'^0(\d:\d\d)', r'\1', strt) strt = re.sub(r'^0(\d:\d\d)', r'\1', strt)
@ -165,7 +177,6 @@ class sbdatetime(datetime.datetime):
('<span class="time-sec">%s</span>' % match.group(5), '')[None is match.group(5)], ('<span class="time-sec">%s</span>' % match.group(5), '')[None is match.group(5)],
('<span class="time-am-pm">%s</span>' % match.group(6), '')[None is match.group(6)])) ('<span class="time-am-pm">%s</span>' % match.group(6), '')[None is match.group(6)]))
finally:
sbdatetime.setlocale(setlocale=setlocale, use_has_locale=sbdatetime.has_locale) sbdatetime.setlocale(setlocale=setlocale, use_has_locale=sbdatetime.has_locale)
return strt return strt
@ -179,7 +190,11 @@ class sbdatetime(datetime.datetime):
try: try:
obj = (dt, self)[self is not None] obj = (dt, self)[self is not None]
if None is not obj: if None is not obj:
strd = obj.strftime((sickbeard.DATE_PRESET, d_preset)[None is not d_preset]) preset = (sickbeard.DATE_PRESET, d_preset)[None is not d_preset]
try:
strd = obj.strftime(preset)
except ValueError:
strd = obj.replace(tzinfo=None).strftime(preset)
finally: finally:
sbdatetime.setlocale(setlocale=setlocale) sbdatetime.setlocale(setlocale=setlocale)
@ -195,8 +210,12 @@ class sbdatetime(datetime.datetime):
obj = (dt, self)[self is not None] obj = (dt, self)[self is not None]
try: try:
if None is not obj: if None is not obj:
strd = u'%s, %s' % (obj.strftime((sickbeard.DATE_PRESET, d_preset)[None is not d_preset]), preset = (sickbeard.DATE_PRESET, d_preset)[None is not d_preset]
sbdatetime.sbftime(dt, show_seconds, t_preset, False, markup)) try:
strd = obj.strftime(preset),
except ValueError:
strd = obj.replace(tzinfo=None).strftime(preset)
strd = u'%s, %s' % (strd, sbdatetime.sbftime(dt, show_seconds, t_preset, False, markup))
finally: finally:
sbdatetime.setlocale(use_has_locale=sbdatetime.has_locale) sbdatetime.setlocale(use_has_locale=sbdatetime.has_locale)