From 58e0b58a0f7b584245e6f9e824a85636fd51edf9 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 17 May 2014 00:30:21 -0700 Subject: [PATCH] Added a timezone display option so that you can either display the date/time via your local timezone or the show's network timezone. --- .../interfaces/default/config_general.tmpl | 13 +++++++++++- gui/slick/interfaces/default/displayShow.tmpl | 2 +- sickbeard/__init__.py | 5 ++++- sickbeard/network_timezones.py | 21 ++++++++++--------- sickbeard/webserve.py | 5 ++++- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/gui/slick/interfaces/default/config_general.tmpl b/gui/slick/interfaces/default/config_general.tmpl index cba94756..cda33051 100644 --- a/gui/slick/interfaces/default/config_general.tmpl +++ b/gui/slick/interfaces/default/config_general.tmpl @@ -359,7 +359,18 @@ #end for - Note: Seconds are only shown on the History Page. + + Note: Seconds are only shown on the History Page. + + + +
+
diff --git a/gui/slick/interfaces/default/displayShow.tmpl b/gui/slick/interfaces/default/displayShow.tmpl index 4389f6c2..d6e3e8be 100644 --- a/gui/slick/interfaces/default/displayShow.tmpl +++ b/gui/slick/interfaces/default/displayShow.tmpl @@ -271,7 +271,7 @@ #end if $epResult["name"] - #if int($epResult["airdate"]) == 1 then "never" else $sbdatetime.sbdatetime.sbfdate($network_timezones.parse_date_time($epResult["airdate"],$show.airs,$show.network,True))# + #if int($epResult["airdate"]) == 1 then "never" else $sbdatetime.sbdatetime.sbfdate($network_timezones.parse_date_time($epResult["airdate"],$show.airs,$show.network))# #if $epLoc and $show._location and $epLoc.lower().startswith($show._location.lower()): #set $epLoc = os.path.basename($epLoc[len($show._location)+1:]) diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index 8c0adde4..008921f0 100644 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -388,6 +388,7 @@ COMING_EPS_MISSED_RANGE = None DATE_PRESET = None TIME_PRESET = None TIME_PRESET_W_SECONDS = None +TIMEZONE_DISPLAY = None USE_SUBTITLES = False SUBTITLES_LANGUAGES = [] @@ -437,7 +438,7 @@ def initialize(consoleLogging=True): USE_PUSHBULLET, PUSHBULLET_NOTIFY_ONSNATCH, PUSHBULLET_NOTIFY_ONDOWNLOAD, PUSHBULLET_NOTIFY_ONSUBTITLEDOWNLOAD, PUSHBULLET_API, PUSHBULLET_DEVICE, \ versionCheckScheduler, VERSION_NOTIFY, AUTO_UPDATE, PROCESS_AUTOMATICALLY, UNPACK, \ KEEP_PROCESSED_DIR, PROCESS_METHOD, TV_DOWNLOAD_DIR, MIN_SEARCH_FREQUENCY, DEFAULT_UPDATE_FREQUENCY, MIN_UPDATE_FREQUENCY, UPDATE_FREQUENCY, \ - showQueueScheduler, searchQueueScheduler, ROOT_DIRS, CACHE_DIR, ACTUAL_CACHE_DIR, \ + showQueueScheduler, searchQueueScheduler, ROOT_DIRS, CACHE_DIR, ACTUAL_CACHE_DIR, TIMEZONE_DISPLAY, \ NAMING_PATTERN, NAMING_MULTI_EP, NAMING_FORCE_FOLDERS, NAMING_ABD_PATTERN, NAMING_CUSTOM_ABD, NAMING_SPORTS_PATTERN, NAMING_CUSTOM_SPORTS, NAMING_STRIP_YEAR, \ RENAME_EPISODES, AIRDATE_EPISODES, properFinderScheduler, PROVIDER_ORDER, autoPostProcesserScheduler, \ WOMBLE, OMGWTFNZBS, OMGWTFNZBS_USERNAME, OMGWTFNZBS_APIKEY, providerList, newznabProviderList, torrentRssProviderList, \ @@ -857,6 +858,7 @@ def initialize(consoleLogging=True): DATE_PRESET = check_setting_str(CFG, 'GUI', 'date_preset', '%x') TIME_PRESET_W_SECONDS = check_setting_str(CFG, 'GUI', 'time_preset', '%I:%M:%S %p') TIME_PRESET = TIME_PRESET_W_SECONDS.replace(u":%S", u"") + TIMEZONE_DISPLAY = check_setting_str(CFG, 'GUI', 'timezone_display', 'network') NEWZNAB_DATA = check_setting_str(CFG, 'Newznab', 'newznab_data', '') newznabProviderList = providers.getNewznabProviderList(NEWZNAB_DATA) @@ -1645,6 +1647,7 @@ def save_config(): new_config['GUI']['coming_eps_missed_range'] = int(COMING_EPS_MISSED_RANGE) new_config['GUI']['date_preset'] = DATE_PRESET new_config['GUI']['time_preset'] = TIME_PRESET_W_SECONDS + new_config['GUI']['timezone_display'] = TIMEZONE_DISPLAY new_config['Subtitles'] = {} new_config['Subtitles']['use_subtitles'] = int(USE_SUBTITLES) diff --git a/sickbeard/network_timezones.py b/sickbeard/network_timezones.py index 081ca411..7f9f5b39 100644 --- a/sickbeard/network_timezones.py +++ b/sickbeard/network_timezones.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with Sick Beard. If not, see . +import sickbeard from lib.dateutil import tz import lib.dateutil.zoneinfo from sickbeard import db @@ -225,7 +226,7 @@ def get_network_timezone(network, network_dict): # parse date and time string into local time -def parse_date_time(d, t, network, local=False): +def parse_date_time(d, t, network): if network_dict is None: load_network_dict() mo = time_regex.search(t) @@ -257,16 +258,16 @@ def parse_date_time(d, t, network, local=False): if hr < 0 or hr > 23 or m < 0 or m > 59: hr = 0 m = 0 - te = datetime.datetime.fromordinal(helpers.tryInt(d)) - foreign_timezone = get_network_timezone(network, network_dict) - foreign_naive = datetime.datetime(te.year, te.month, te.day, hr, m, tzinfo=foreign_timezone) - try: - if local: - return foreign_naive.replace(tzinfo=sb_timezone).astimezone(sb_timezone) - return foreign_naive.astimezone(sb_timezone) - except (ValueError): - return foreign_naive + te = datetime.datetime.fromordinal(helpers.tryInt(d)) + try: + if sickbeard.TIMEZONE_DISPLAY == 'local': + return datetime.datetime(te.year, te.month, te.day, hr, m, tzinfo=sb_timezone) + else: + foreign_timezone = get_network_timezone(network, network_dict) + return datetime.datetime(te.year, te.month, te.day, hr, m, tzinfo=foreign_timezone) + except: + return datetime.datetime(te.year, te.month, te.day, hr, m) def test_timeformat(t): mo = time_regex.search(t) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 57f6ca70..ca98a765 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -1010,7 +1010,8 @@ class ConfigGeneral: update_shows_on_start=None, update_frequency=None, launch_browser=None, web_username=None, use_api=None, api_key=None, web_password=None, version_notify=None, enable_https=None, https_cert=None, https_key=None, handle_reverse_proxy=None, sort_article=None, auto_update=None, proxy_setting=None, - anon_redirect=None, git_path=None, calendar_unprotected=None, date_preset=None, time_preset=None, indexer_default=None,): + anon_redirect=None, git_path=None, calendar_unprotected=None, date_preset=None, time_preset=None, + indexer_default=None, timezone_display=None): results = [] @@ -1047,6 +1048,8 @@ class ConfigGeneral: sickbeard.TIME_PRESET_W_SECONDS = time_preset sickbeard.TIME_PRESET = sickbeard.TIME_PRESET_W_SECONDS.replace(u":%S", u"") + sickbeard.TIMEZONE_DISPLAY = timezone_display + if not config.change_LOG_DIR(log_dir, web_log): results += ["Unable to create directory " + os.path.normpath(log_dir) + ", log directory not changed."]