diff --git a/resources/lib/stillwatching.py b/resources/lib/stillwatching.py index a51d1def..0212f65b 100644 --- a/resources/lib/stillwatching.py +++ b/resources/lib/stillwatching.py @@ -6,7 +6,7 @@ from platform import machine from xbmcgui import WindowXMLDialog from statichelper import from_unicode -from utils import localize_time +from utils import localize_date, localize_time ACTION_PLAYER_STOP = 13 ACTION_NAV_BACK = 92 @@ -54,7 +54,7 @@ def set_info(self): self.setProperty('season', str(self.item.get('season', ''))) self.setProperty('episode', str(self.item.get('episode', ''))) self.setProperty('seasonepisode', episode_info) - self.setProperty('year', str(self.item.get('firstaired', ''))) + self.setProperty('year', localize_date(self.item.get('firstaired', ''))) self.setProperty('rating', rating) self.setProperty('playcount', str(self.item.get('playcount', 0))) self.setProperty('runtime', str(self.item.get('runtime', ''))) diff --git a/resources/lib/upnext.py b/resources/lib/upnext.py index a95b837a..9815cad4 100644 --- a/resources/lib/upnext.py +++ b/resources/lib/upnext.py @@ -7,7 +7,7 @@ from xbmc import Player from xbmcgui import WindowXMLDialog from statichelper import from_unicode -from utils import get_setting_bool, localize, localize_time +from utils import get_setting_bool, localize, localize_date, localize_time ACTION_PLAYER_STOP = 13 ACTION_NAV_BACK = 92 @@ -59,7 +59,7 @@ def set_info(self): self.setProperty('season', str(self.item.get('season', ''))) self.setProperty('episode', str(self.item.get('episode', ''))) self.setProperty('seasonepisode', episode_info) - self.setProperty('year', str(self.item.get('firstaired', ''))) + self.setProperty('year', localize_date(self.item.get('firstaired', ''))) self.setProperty('rating', rating) self.setProperty('playcount', str(self.item.get('playcount', 0))) self.setProperty('runtime', str(self.item.get('runtime', ''))) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 5f6bfdae..15204c0f 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -4,6 +4,8 @@ from __future__ import absolute_import, division, unicode_literals import sys import json +from datetime import date +from re import split as re_split from xbmc import executeJSONRPC, getInfoLabel, getRegion, log as xlog, LOGDEBUG, LOGINFO from xbmcaddon import Addon from xbmcgui import Window @@ -202,6 +204,23 @@ def localize(string_id): return ADDON.getLocalizedString(string_id) +def localize_date(date_string): + """Localize date format""" + date_format = getRegion('dateshort') + + try: + # A number of assumptions are made here about date_string + # format to avoid having to import dateutil or similar + date_object = date(*( + int(part) + for part in re_split(r'[\W]', date_string)[:3] + )) + except ValueError: + return date_string + + return date_object.strftime(date_format) + + def localize_time(time): """Localize time format""" time_format = getRegion('time')