2024-05-16 10:37:37 -04:00
|
|
|
import os
|
2025-08-15 15:02:54 -04:00
|
|
|
from zoneinfo import ZoneInfo
|
2024-05-16 10:37:37 -04:00
|
|
|
|
|
|
|
|
from dateutil import parser
|
|
|
|
|
|
2025-08-15 15:02:54 -04:00
|
|
|
local_timezone = ZoneInfo(os.getenv("TIMEZONE", "America/New_York"))
|
2024-05-16 10:37:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def utc_string_to_aware_gmt_datetime(date):
|
|
|
|
|
"""
|
|
|
|
|
Date can either be a string, naïve UTC datetime or an aware UTC datetime
|
|
|
|
|
Returns an aware local datetime, essentially the time you'd see on your clock
|
|
|
|
|
"""
|
|
|
|
|
date = parser.parse(date)
|
2025-08-15 15:02:54 -04:00
|
|
|
forced_utc = date.replace(tzinfo=ZoneInfo("UTC"))
|
2024-05-16 10:37:37 -04:00
|
|
|
return forced_utc.astimezone(local_timezone)
|