Skip to content

Commit

Permalink
Adding to_epoch support for timezones
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog committed Nov 13, 2024
1 parent fae7b8c commit cc5f8c5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion brewtils/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ def to_epoch(value):
if isinstance(value, int) or isinstance(value, float):
return value

if value.tzinfo is not None and value.tzinfo is not datetime.timezone.utc:
value = value.replace(tzinfo=datetime.timezone.utc)

return utils.timestamp_ms(value)

@staticmethod
def from_epoch(value):
# If already in datetime form just return it
if isinstance(value, datetime.datetime):
return value.replace(tzinfo=datetime.timezone.utc)
if value.tzinfo is None:
return value.replace(tzinfo=datetime.timezone.utc)
return value

return utils.from_timestamp_ms(value).replace(tzinfo=datetime.timezone.utc)

Expand Down

0 comments on commit cc5f8c5

Please sign in to comment.