Skip to content

Commit

Permalink
Fix the utcfromtimestamp deprecation finally
Browse files Browse the repository at this point in the history
  • Loading branch information
corruptbear committed Jul 1, 2024
1 parent deac89e commit 4d15641
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion software/management/dashboard/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions software/management/dashboard/tottag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4d15641

Please sign in to comment.