def test_iso8601_to_datetime(private_settings): import django.utils.timezone import pytz private_settings.TIME_ZONE = 'UTC' if hasattr(django.utils.timezone.get_default_timezone, 'cache_clear'): django.utils.timezone.get_default_timezone.cache_clear() django.utils.timezone._localtime = None private_settings.USE_TZ = False # UTC ISO8601 -> naive datetime UTC assert iso8601_to_datetime('2010-10-01T10:10:34Z') == datetime.datetime( 2010, 10, 01, 10, 10, 34) # NAIVE ISO8601 -> naive datetime UTC assert iso8601_to_datetime('2010-10-01T10:10:34') == datetime.datetime( 2010, 10, 01, 10, 10, 34) private_settings.USE_TZ = True # UTC+1h ISO8601 -> Aware datetime UTC assert iso8601_to_datetime( '2010-10-01T10:10:34+01:00') == datetime.datetime(2010, 10, 01, 9, 10, 34, tzinfo=pytz.utc) # Naive ISO8601 -> Aware datetime UTC assert iso8601_to_datetime('2010-10-01T10:10:34') == datetime.datetime( 2010, 10, 01, 10, 10, 34, tzinfo=pytz.utc)
def get_session_not_on_or_after(self): session_not_on_or_after = self.get('mellon_session', {}).get('session_not_on_or_after') if session_not_on_or_after: return utils.iso8601_to_datetime(session_not_on_or_after) return None