From 59243e06723ce5a5e630c4ce409358fc58411e3e Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Sat, 15 Jun 2024 21:38:58 -0700 Subject: [PATCH] make datetimes timezone-aware --- src/rcutils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rcutils.py b/src/rcutils.py index df7356b..377c8f3 100644 --- a/src/rcutils.py +++ b/src/rcutils.py @@ -7,7 +7,7 @@ import os from binascii import hexlify -from datetime import datetime +from datetime import datetime, timedelta, timezone from re import search as re_search from re import sub as re_sub from struct import pack as struct_pack @@ -26,6 +26,8 @@ _filetime_quantum = 1e-7 _filetime_epoch_offset = 116444736000000000 +UTC = timezone(timedelta(0)) + def FileTime2UnixTime(x: Number) -> float: "Convert a FileTime to Unix timestamp" @@ -34,7 +36,7 @@ def FileTime2UnixTime(x: Number) -> float: def FileTime2DateTime(x: Number) -> datetime: "Convert a FileTime to Python DateTime" - return datetime.fromtimestamp(FileTime2UnixTime(x)) + return datetime.fromtimestamp(FileTime2UnixTime(x), UTC) def UnixTime2FileTime(x: Number) -> int: