Finalize utility format and usage

- Renamed to `format_dt`
- Only show values in UTC and omit "UTC" display
This commit is contained in:
awsr
2025-12-28 01:25:23 -08:00
parent 4d3dfac0a0
commit 885cbcd118
2 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -25,10 +25,10 @@ def parse_isotime(time_string: str) -> datetime:
raise ValueError(f"Unexpected time string format: '{time_string}'")
def format_eztime(d: datetime, local = False) -> str:
def format_dt(d: datetime) -> str:
if d.tzinfo is None:
return d.strftime('%Y-%m-%d %H:%M')
return d.astimezone(None if local else timezone.utc).strftime('%Y-%m-%d %H:%M %Z')
return d.astimezone(timezone.utc).strftime('%Y-%m-%d %H:%M:%S') # Ensure UTC time is shown (just in case)
def ts2utc(timestamp: int) -> datetime:
@@ -166,7 +166,7 @@ class Extension:
except Exception:
self.branch = 'unknown'
self.commit_hash = head.hexsha
self.version = f"<p>{self.commit_hash[:8]}</p><p>{format_eztime(datetime.fromtimestamp(self.commit_date, timezone.utc))}</p>"
self.version = f"<p>{self.commit_hash[:8]}</p><p>{format_dt(ts2utc(self.commit_date))}</p>"
except Exception as ex:
shared.log.error(f"Extension: failed reading data from git repo={self.name}: {ex}")
self.remote = None
+6 -6
View File
@@ -108,10 +108,10 @@ def check_updates(_id_task, disable_list, search_text, sort_column):
ext.git_fetch()
ext.read_info(True)
commit_date = ext.commit_date or 1577836800
shared.log.info(f'Extensions updated: {ext.name} {ext.commit_hash[:8]} {extensions.format_eztime(datetime.fromtimestamp(commit_date, timezone.utc), True)}')
shared.log.info(f'Extensions updated: {ext.name} {ext.commit_hash[:8]} {extensions.format_dt(extensions.ts2utc(commit_date))}')
else:
commit_date = ext.commit_date or 1577836800
shared.log.debug(f'Extensions no update available: {ext.name} {ext.commit_hash[:8]} {extensions.format_eztime(datetime.fromtimestamp(commit_date, timezone.utc), True)}')
shared.log.debug(f'Extensions no update available: {ext.name} {ext.commit_hash[:8]} {extensions.format_dt(extensions.ts2utc(commit_date))}')
except FileNotFoundError as e:
if 'FETCH_HEAD' not in str(e):
raise
@@ -229,10 +229,10 @@ def update_extension(extension_path, search_text, sort_column):
ext.git_fetch()
ext.read_info(True)
commit_date = ext.commit_date or 1577836800
shared.log.info(f'Extensions updated: {ext.name} {ext.commit_hash[:8]} {extensions.format_eztime(datetime.fromtimestamp(commit_date, timezone.utc), True)}')
shared.log.info(f'Extensions updated: {ext.name} {ext.commit_hash[:8]} {extensions.format_dt(extensions.ts2utc(commit_date))}')
else:
commit_date = ext.commit_date or 1577836800
shared.log.info(f'Extensions no update available: {ext.name} {ext.commit_hash[:8]} {extensions.format_eztime(datetime.fromtimestamp(commit_date, timezone.utc), True)}')
shared.log.info(f'Extensions no update available: {ext.name} {ext.commit_hash[:8]} {extensions.format_dt(extensions.ts2utc(commit_date))}')
except FileNotFoundError as e:
if 'FETCH_HEAD' not in str(e):
raise
@@ -311,7 +311,7 @@ def create_html(search_text, sort_column):
def dt(x: str):
val = ext.get(x, None)
try:
return extensions.format_eztime(extensions.parse_isotime(val)) if val is not None else "N/A"
return extensions.format_dt(extensions.parse_isotime(val)) if val is not None else "N/A"
except Exception:
return 'N/A'
@@ -331,7 +331,7 @@ def create_html(search_text, sort_column):
local_ver_date = datetime.fromtimestamp(ext['commit_date'], timezone.utc) # TZ-aware
update_available = (installed is not None) and (ext['remote'] is not None) and (updated > local_ver_date) # TZ-aware
if update_available:
debug(f'Extension update available: name={ext["name"]} updated={extensions.format_eztime(updated), True} commit={extensions.format_eztime(local_ver_date), True}') # TZ-aware
debug(f'Extension update available: name={ext["name"]} updated={extensions.format_dt(updated)} commit={extensions.format_dt(local_ver_date)}') # TZ-aware
ext['sort_user'] = f"{'0' if ext['is_builtin'] else '1'}{'1' if ext['installed'] else '0'}{ext.get('name', '')}"
ext['sort_enabled'] = f"{'0' if ext['enabled'] else '1'}{'1' if ext['is_builtin'] else '0'}{'1' if ext['installed'] else '0'}{ext.get('updated', '2000-01-01T00:00Z')}"
ext['sort_update'] = f"{'1' if update_available else '0'}{'1' if ext['installed'] else '0'}{ext.get('updated', '2000-01-01T00:00Z')}"