From 4d156417fb7992a734cf0ef98df08cd3babde7c0 Mon Sep 17 00:00:00 2001 From: corruptbear Date: Mon, 1 Jul 2024 09:47:10 -0700 Subject: [PATCH] Fix the utcfromtimestamp deprecation finally --- software/management/dashboard/processing.py | 2 +- software/management/dashboard/tottag.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/software/management/dashboard/processing.py b/software/management/dashboard/processing.py index 1430547a..0eb713fc 100755 --- a/software/management/dashboard/processing.py +++ b/software/management/dashboard/processing.py @@ -129,7 +129,7 @@ def get_off_and_on_charger_times(data, label, peak_width=50, window_size=10, vis combined = {k: off.get(k, "") + on.get(k, "") for k in sorted(set(off) | set(on))} for key in combined: - local_time = pytz.utc.localize(datetime.utcfromtimestamp(key.timestamp())).astimezone(pytz.timezone(tzlocal.get_localzone_name())).strftime('%Y-%m-%d %H:%M:%S %Z') + local_time = datetime.fromtimestamp(key.timestamp(), timezone.utc).astimezone(pytz.timezone(tzlocal.get_localzone_name())).strftime('%Y-%m-%d %H:%M:%S %Z') print(key.strftime('%Y-%m-%d %H:%M:%S %Z'), local_time, combined[key]) if visualize: diff --git a/software/management/dashboard/tottag.py b/software/management/dashboard/tottag.py index 9376dfa5..c3b03d7a 100755 --- a/software/management/dashboard/tottag.py +++ b/software/management/dashboard/tottag.py @@ -91,12 +91,12 @@ def pack_datetime(time_zone, date_string, time_string, daily): def unpack_datetime(time_zone, start_timestamp, timestamp): date_string = None if start_timestamp is None: - local_datetime = pytz.utc.localize(datetime.datetime.utcfromtimestamp(timestamp)).astimezone(pytz.timezone(time_zone)) + local_datetime = datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc).astimezone(pytz.timezone(time_zone)) date_string = local_datetime.strftime('%m/%d/%Y') time_string = local_datetime.strftime('%H:%M') seconds_string = local_datetime.strftime('%S') else: - offset = pytz.utc.localize(datetime.datetime.utcfromtimestamp(start_timestamp)).astimezone(pytz.timezone(time_zone)).utcoffset().total_seconds() + offset = datetime.datetime.fromtimestamp(start_timestamp, datetime.timezone.utc).astimezone(pytz.timezone(time_zone)).utcoffset().total_seconds() hours = int((timestamp + offset) / 3600) time_string = '%02d:%02d'%(hours, int((timestamp + offset - (hours*3600)) / 60)) seconds_string = '%02d'%(timestamp % 60)