Files
notifications-api/notifications_utils/timezones.py
Carlo Costino 99edc88197 Localize notification_utils to the API
This changeset pulls in all of the notification_utils code directly into the API and removes it as an external dependency.  We are doing this to cut down on operational maintenance of the project and will begin removing parts of it no longer needed for the API.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2024-05-16 10:17:45 -04:00

17 lines
474 B
Python

import os
import pytz
from dateutil import parser
local_timezone = pytz.timezone(os.getenv("TIMEZONE", "America/New_York"))
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)
forced_utc = date.replace(tzinfo=pytz.utc)
return forced_utc.astimezone(local_timezone)