added utils function for regional date, use for scheduler notifications as well

This commit is contained in:
Rob Weber 2019-08-20 11:50:46 -05:00
parent f0d8e297a9
commit 6c33e7c9ba
3 changed files with 13 additions and 5 deletions

View File

@ -428,7 +428,7 @@ class XbmcBackup:
date_time = datetime(int(dirName[0:4]),int(dirName[4:6]),int(dirName[6:8]),int(dirName[8:10]),int(dirName[10:12]))
#format the string based on region settings
result = "%s %s" % (date_time.strftime(xbmc.getRegion('dateshort')),date_time.strftime(xbmc.getRegion('time')))
result = utils.getRegionalTimestamp(date_time, ['dateshort','time'])
return result

View File

@ -29,6 +29,14 @@ def setSetting(name,value):
def getString(string_id):
return __Addon.getLocalizedString(string_id)
def getRegionalTimestamp(date_time,dateformat=['dateshort']):
result = ''
for aFormat in dateformat:
result = result + ("%s " % date_time.strftime(xbmc.getRegion(aFormat)))
return result.strip()
def encode(string):
result = ''

View File

@ -1,7 +1,7 @@
import xbmc
import xbmcvfs
import xbmcgui
import datetime
from datetime import datetime
import time
import resources.lib.utils as utils
from resources.lib.croniter import croniter
@ -123,12 +123,12 @@ class BackupScheduler:
#find the cron expression and get the next run time
cron_exp = self.parseSchedule()
cron_ob = croniter(cron_exp,datetime.datetime.fromtimestamp(now))
cron_ob = croniter(cron_exp,datetime.fromtimestamp(now))
new_run_time = cron_ob.get_next(float)
if(new_run_time != self.next_run):
self.next_run = new_run_time
utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
utils.log("scheduler will run again on " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run),['dateshort','time']))
#write the next time to a file
fh = xbmcvfs.File(self.next_run_path, 'w')
@ -137,7 +137,7 @@ class BackupScheduler:
#only show when not in silent mode
if(progress_mode != 2):
utils.showNotification(utils.getString(30081) + " " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
utils.showNotification(utils.getString(30081) + " " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run),['dateshort','time']))
def settingsChanged(self):
current_enabled = utils.getSetting("enable_scheduler")