Source code for arguslib.misc.times

import datetime
import pytz


[docs] def convert_to_london_naive(dt: datetime.datetime) -> datetime.datetime: """ Converts a datetime object to a naive datetime in the 'Europe/London' timezone. Args: dt: The input datetime object. If naive, it's assumed to be in UTC. If aware, it's converted from its current timezone. Returns: A naive datetime object representing the equivalent time in London. """ # Define the target timezone london_tz = pytz.timezone("Europe/London") # 1. If the datetime is naive, assume it's UTC and make it timezone-aware. if dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None: dt_utc = pytz.utc.localize(dt) # 2. If it's already aware, we'll just use it as is for conversion. else: dt_utc = dt # 3. Convert the UTC datetime to the London timezone. # The result will be a timezone-aware datetime in the London timezone. dt_local_aware = dt_utc.astimezone(london_tz) # 4. Remove the timezone information to make the datetime naive. dt_local_naive = dt_local_aware.replace(tzinfo=None) return dt_local_naive