Simplify datetime_to_timestamp

This commit is contained in:
tcely 2025-04-21 15:25:58 -04:00 committed by GitHub
parent 7ae75edffc
commit f8a2eeeb97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,17 +18,12 @@ def subtract_epoch(arg_dt, /):
return utc_dt - epoch
def datetime_to_timestamp(arg_dt, /):
def datetime_to_timestamp(arg_dt, /, *, integer=True):
timestamp = subtract_epoch(arg_dt).total_seconds()
try:
timestamp_int = int(timestamp)
except (TypeError, ValueError,):
pass
else:
return timestamp_int
if not integer:
return timestamp
return int(timestamp)
def timestamp_to_datetime(seconds, /):
return add_epoch(seconds=seconds).astimezone(utc_tz)