From c789c8a14c29a93e7024d3f3c726601ad6d1d465 Mon Sep 17 00:00:00 2001 From: Prinz23 Date: Mon, 15 Aug 2016 01:16:35 +0200 Subject: [PATCH 1/2] Add Fallback to display date without timezone info (for windows historical dates) --- sickbeard/sbdatetime.py | 87 +++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/sickbeard/sbdatetime.py b/sickbeard/sbdatetime.py index 4be1c355..4cc4673c 100644 --- a/sickbeard/sbdatetime.py +++ b/sickbeard/sbdatetime.py @@ -104,6 +104,14 @@ class static_or_instance(object): class sbdatetime(datetime.datetime): 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 def convert_to_setting(self, dt=None): obj = (dt, self)[self is not None] @@ -121,7 +129,7 @@ class sbdatetime(datetime.datetime): try: if None is use_has_locale or use_has_locale: locale.setlocale(locale.LC_TIME, locale_str) - except: + except locale.Error: if None is not use_has_locale: sbdatetime.has_locale = False pass @@ -133,41 +141,44 @@ class sbdatetime(datetime.datetime): sbdatetime.setlocale(setlocale=setlocale, use_has_locale=sbdatetime.has_locale, locale_str='us_US') strt = '' - try: - obj = (dt, self)[self is not None] - if None is not obj: - tmpl = (((sickbeard.TIME_PRESET, sickbeard.TIME_PRESET_W_SECONDS)[show_seconds]), - t_preset)[None is not t_preset] - tmpl = (tmpl.replace(':%S', ''), tmpl)[show_seconds] - strt = obj.strftime(tmpl.replace('%P', '%p')) + obj = (dt, self)[self is not None] + if None is not obj: + tmpl = (((sickbeard.TIME_PRESET, sickbeard.TIME_PRESET_W_SECONDS)[show_seconds]), + t_preset)[None is not t_preset] + tmpl = (tmpl.replace(':%S', ''), tmpl)[show_seconds] + + 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: + strt = re.sub(r'^0(\d:\d\d)', r'\1', strt) + + if re.search(r'(?im)%p$', tmpl): + if '%p' in tmpl: + strt = strt.upper() + elif '%P' in tmpl: + strt = strt.lower() if sickbeard.TRIM_ZERO: - strt = re.sub(r'^0(\d:\d\d)', r'\1', strt) + strt = re.sub(r'(?im)^(\d+)(?::00)?(\s?[ap]m)', r'\1\2', strt) - if re.search(r'(?im)%p$', tmpl): - if '%p' in tmpl: - strt = strt.upper() - elif '%P' in tmpl: - strt = strt.lower() + if markup: + match = re.search(r'(?im)(\d{1,2})(?:(.)(\d\d)(?:(.)(\d\d))?)?(?:\s?([ap]m))?$', strt) + if match: + strt = ('%s%s%s%s%s%s' % ( + ('%s' % match.group(1), '')[None is match.group(1)], + ('%s' % match.group(2), '')[None is match.group(2)], + ('%s' % match.group(3), '')[None is match.group(3)], + ('%s' % match.group(4), '')[None is match.group(4)], + ('%s' % match.group(5), '')[None is match.group(5)], + ('%s' % match.group(6), '')[None is match.group(6)])) - if sickbeard.TRIM_ZERO: - strt = re.sub(r'(?im)^(\d+)(?::00)?(\s?[ap]m)', r'\1\2', strt) - - if markup: - match = re.search(r'(?im)(\d{1,2})(?:(.)(\d\d)(?:(.)(\d\d))?)?(?:\s?([ap]m))?$', strt) - if match: - strt = ('%s%s%s%s%s%s' % ( - ('%s' % match.group(1), '')[None is match.group(1)], - ('%s' % match.group(2), '')[None is match.group(2)], - ('%s' % match.group(3), '')[None is match.group(3)], - ('%s' % match.group(4), '')[None is match.group(4)], - ('%s' % match.group(5), '')[None is match.group(5)], - ('%s' % match.group(6), '')[None is match.group(6)])) - - finally: - sbdatetime.setlocale(setlocale=setlocale, use_has_locale=sbdatetime.has_locale) - return strt + sbdatetime.setlocale(setlocale=setlocale, use_has_locale=sbdatetime.has_locale) + return strt # display Date in SickGear Format @static_or_instance @@ -179,7 +190,11 @@ class sbdatetime(datetime.datetime): try: obj = (dt, self)[self is not None] 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: sbdatetime.setlocale(setlocale=setlocale) @@ -195,8 +210,12 @@ class sbdatetime(datetime.datetime): obj = (dt, self)[self is not None] try: if None is not obj: - strd = u'%s, %s' % (obj.strftime((sickbeard.DATE_PRESET, d_preset)[None is not d_preset]), - sbdatetime.sbftime(dt, show_seconds, t_preset, False, markup)) + 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) + strd = u'%s, %s' % (strd, sbdatetime.sbftime(dt, show_seconds, t_preset, False, markup)) finally: sbdatetime.setlocale(use_has_locale=sbdatetime.has_locale) From 05956804dfe070f67b745e54aa04dcb0705f1224 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Fri, 14 Oct 2016 14:29:44 +0100 Subject: [PATCH 2/2] Change fuzzyMoment to handle air dates before ~1970 on display show page. Change ensure sbdatetime functions return formatted string instead of tuple. Change limit availability of fuzzy date functions on General Config/Interface to English locale systems. Update moment.js 2.6 to 2.15.1 --- CHANGES.md | 4 + .../interfaces/default/config_general.tmpl | 6 +- gui/slick/interfaces/default/displayShow.tmpl | 2 +- gui/slick/js/fuzzyMoment.js | 46 +- gui/slick/js/moment/moment.min.js | 493 +++++++++++++++++- sickbeard/sbdatetime.py | 40 +- 6 files changed, 541 insertions(+), 50 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f14c11c6..e3fc6625 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ * Update Hachoir library 1.3.4 (r1383) to 1.3.4 (r1435) * Update html5lib 0.999 to 0.99999999/1.0b9 (46dae3d) * Update IMDb 5.0 to 5.1dev20160106 +* Update moment.js 2.6 to 2.15.1 * Update PNotify library 2.0.1 to 2.1.0 * Update profilehooks 1.4 to 1.8.2.dev0 (ee3f1a8) * Update Requests library 2.7.0 (5d6d1bc) to 2.9.1 (a1c9b84) @@ -181,6 +182,8 @@ * Change hachoir_parser to close input stream if no parser is found e.g. due to file corruption * Change reduce time taken to parse avi RIFF metadata during post processing and other times * Change avi metadata extraction is more fault tolerant and the chance of hanging due to corrupt avi files is reduced +* Change fuzzyMoment to handle air dates before ~1970 on display show page +* Change limit availability of fuzzy date functions on General Config/Interface to English locale systems [develop changelog] * Change send nzb data to NZBGet for Anizb instead of url @@ -205,6 +208,7 @@ * Change add helper function to validate acceptable image file extension * Change make sure avi files are closed if an error occurs * Change refactor hachoir scan_index for non RIFF file processing +* Change ensure sbdatetime functions return formatted string instead of tuple ### 0.11.16 (2016-10-16 17:30:00 UTC) diff --git a/gui/slick/interfaces/default/config_general.tmpl b/gui/slick/interfaces/default/config_general.tmpl index 3dd852b1..505ab314 100644 --- a/gui/slick/interfaces/default/config_general.tmpl +++ b/gui/slick/interfaces/default/config_general.tmpl @@ -332,6 +332,10 @@ +#if not $sbdatetime.is_locale_eng() + + +#else
- +#end if