Move current date calculation to a function
This commit is contained in:
@@ -8,7 +8,7 @@ from dateutil import tz
|
||||
|
||||
import xbmcgui
|
||||
|
||||
from .utils import datetime_from_string, get_art_url, image_url, kodi_version
|
||||
from .utils import datetime_from_string, get_art_url, image_url, kodi_version, get_current_datetime
|
||||
from .lazylogger import LazyLogger
|
||||
from six import ensure_text
|
||||
|
||||
@@ -403,10 +403,8 @@ def add_gui_item(url, item_details, display_options, folder=True, default_sort=F
|
||||
end_time = datetime_from_string(item_details.program_end_date)
|
||||
|
||||
duration = (end_time - start_time).total_seconds()
|
||||
# Get current date in UTC to compare against server
|
||||
now = datetime.utcnow()
|
||||
now_dt = now.replace(tzinfo=tz.tzutc())
|
||||
time_done = (now_dt - start_time).total_seconds()
|
||||
now = get_current_datetime()
|
||||
time_done = (now - start_time).total_seconds()
|
||||
percentage_done = (float(time_done) / float(duration)) * 100.0
|
||||
capped_percentage = int(percentage_done)
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import socket
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime
|
||||
from dateutil import tz
|
||||
|
||||
import xbmcaddon
|
||||
import xbmcgui
|
||||
@@ -14,7 +13,7 @@ import xbmc
|
||||
from .kodi_utils import HomeWindow
|
||||
from .jellyfin import API
|
||||
from .lazylogger import LazyLogger
|
||||
from .utils import datetime_from_string, translate_string, save_user_details, load_user_details
|
||||
from .utils import datetime_from_string, translate_string, save_user_details, load_user_details, get_current_datetime
|
||||
from .dialogs import QuickConnectDialog
|
||||
|
||||
log = LazyLogger(__name__)
|
||||
@@ -369,10 +368,7 @@ def create_user_listitem(server, user):
|
||||
Create a user listitem for the user selection screen
|
||||
'''
|
||||
config = user.get("Configuration")
|
||||
# Get current time in UTC
|
||||
now = datetime.utcnow()
|
||||
utc = tz.tzutc()
|
||||
now_dt = now.replace(tzinfo=utc)
|
||||
now = get_current_datetime()
|
||||
if config is not None:
|
||||
name = user.get("Name")
|
||||
time_ago = ""
|
||||
@@ -380,7 +376,7 @@ def create_user_listitem(server, user):
|
||||
# Calculate how long it's been since the user was last active
|
||||
if last_active:
|
||||
last_active_date = datetime_from_string(last_active)
|
||||
ago = now_dt - last_active_date
|
||||
ago = now - last_active_date
|
||||
# Check days
|
||||
if ago.days > 0:
|
||||
time_ago += ' {}d'.format(ago.days)
|
||||
|
||||
@@ -111,6 +111,15 @@ def datetime_from_string(time_string):
|
||||
return utc_dt
|
||||
|
||||
|
||||
def get_current_datetime():
|
||||
# Get current time in UTC
|
||||
now = datetime.utcnow()
|
||||
utc = tz.tzutc()
|
||||
now_dt = now.replace(tzinfo=utc)
|
||||
|
||||
return now_dt
|
||||
|
||||
|
||||
def convert_size(size_bytes):
|
||||
if size_bytes == 0:
|
||||
return "0B"
|
||||
|
||||
Reference in New Issue
Block a user