fix(utils): datetime_to_epoch function is fixed to timezone aware epoch (#37979)

This commit is contained in:
Türker Ziya Ercin
2026-02-15 18:36:18 +03:00
committed by GitHub
parent cbf153845e
commit 440602ef34
2 changed files with 7 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ EPOCH = datetime(1970, 1, 1)
def datetime_to_epoch(dttm: datetime) -> float:
"""Convert datetime to milliseconds to epoch"""
if dttm.tzinfo:
dttm = dttm.replace(tzinfo=pytz.utc)
dttm = dttm.astimezone(pytz.utc)
epoch_with_tz = pytz.utc.localize(EPOCH)
return (dttm - epoch_with_tz).total_seconds() * 1000
return (dttm - EPOCH).total_seconds() * 1000