Skip to content

Commit

Permalink
make datetimes timezone-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuethe committed Jun 16, 2024
1 parent 577dd9b commit 59243e0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/rcutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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:
Expand Down

0 comments on commit 59243e0

Please sign in to comment.