Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tzinfo: a pytz timezone object, or None (interpreted as UTC).
Returns:
a datetime object in the time zone 'tzinfo'
"""
if pytz is None:
return t.replace(tzinfo=tzinfo)
elif tzinfo:
if not t.tzinfo:
t = pytz.utc.localize(t)
return tzinfo.normalize(t.astimezone(tzinfo))
elif t.tzinfo:
return pytz.utc.normalize(t.astimezone(pytz.utc)).replace(tzinfo=None)
else:
return t
"""Converts 't' to the time zone 'tzinfo'.
Arguments:
t: a datetime object. It may be in any pytz time zone, or it may be
timezone-naive (interpreted as UTC).
tzinfo: a pytz timezone object, or None (interpreted as UTC).
Returns:
a datetime object in the time zone 'tzinfo'
"""
if tzinfo:
if not t.tzinfo:
t = pytz.utc.localize(t)
return tzinfo.normalize(t.astimezone(tzinfo))
elif t.tzinfo:
return pytz.utc.normalize(t.astimezone(pytz.utc)).replace(tzinfo=None)
else:
return t
# even if the temperature rises above 10, don't inactivate the trigger
# if it's less than 2 hours until departure
if not self.active:
return True
local_timezone = timezone(self.timezone)
currentDate = pytz.utc.localize(datetime.utcnow())
local_datetime = local_timezone.localize(
datetime(currentDate.year, currentDate.month, currentDate.day, self.departureHour, self.departureMinute)
)
utc_datetime = pytz.utc.normalize(local_datetime.astimezone(pytz.utc))
if currentDate > utc_datetime:
# departure time already passed today
local_datetime = local_timezone.localize(
datetime(currentDate.year, currentDate.month, currentDate.day, self.departureHour, self.departureMinute) + timedelta(days=1)
)
utc_datetime = pytz.utc.normalize(local_datetime.astimezone(pytz.utc))
return currentDate < (utc_datetime - timedelta(hours=self.maxRunTime/3600))
tzinfo: a pytz timezone object, or None (interpreted as UTC).
Returns:
a datetime object in the time zone 'tzinfo'
"""
if pytz is None:
return t.replace(tzinfo=tzinfo)
elif tzinfo:
if not t.tzinfo:
t = pytz.utc.localize(t)
return tzinfo.normalize(t.astimezone(tzinfo))
elif t.tzinfo:
return pytz.utc.normalize(t.astimezone(pytz.utc)).replace(tzinfo=None)
else:
return t
tzinfo: a pytz timezone object, or None (interpreted as UTC).
Returns:
a datetime object in the time zone 'tzinfo'
"""
if pytz is None:
return t.replace(tzinfo=tzinfo)
elif tzinfo:
if not t.tzinfo:
t = pytz.utc.localize(t)
return tzinfo.normalize(t.astimezone(tzinfo))
elif t.tzinfo:
return pytz.utc.normalize(t.astimezone(pytz.utc)).replace(tzinfo=None)
else:
return t
def render_data(self, state, obj):
# If the datetime object is tz aware, conver it to local time
datetime = getattr(obj, self.field_name)
if settings.USE_TZ:
datetime = pytz.utc.normalize(datetime).\
astimezone(self.timezone)
return date(datetime, self.format)
def format_date_time(date: datetime.datetime):
return pytz.utc.normalize(date).strftime(FHIR_DATE_TIME_FORMAT)
def format(self, v):
if v.tzinfo:
v = pytz.utc.normalize(v)
result = v.strftime("%H:%M:%S")
if v.microsecond:
result += ".{:06d}".format(v.microsecond).rstrip("0")
if v.tzinfo:
result += "Z"
return result
def last_run_at(self, val):
if val:
val = utc.normalize(val)
self._last_run_at = val