Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_apply_timezone_function(self, date, timezone, expected):
result = apply_timezone(date, timezone)
result = result.replace(tzinfo=None)
self.assertEqual(expected, result)
if not self.now.tzinfo:
self.now = self.get_local_tz().localize(self.now)
elif ptz:
_now = datetime.now(ptz)
if 'local' in _settings_tz:
self.now = _now
else:
self.now = apply_timezone(_now, settings.TIMEZONE)
else:
if 'local' not in _settings_tz:
utc_dt = datetime.utcnow()
self.now = apply_timezone(utc_dt, settings.TIMEZONE)
else:
self.now = datetime.now(self.get_local_tz())
date, period = self._parse_date(date_string)
if date:
date = apply_time(date, _time)
if settings.TO_TIMEZONE:
date = apply_timezone(date, settings.TO_TIMEZONE)
if (
not settings.RETURN_AS_TIMEZONE_AWARE or
(settings.RETURN_AS_TIMEZONE_AWARE and
'default' == settings.RETURN_AS_TIMEZONE_AWARE and not ptz)
):
date = date.replace(tzinfo=None)
if ptz:
if self.now.tzinfo:
self.now = self.now.astimezone(ptz)
else:
self.now = ptz.localize(self.now)
if not self.now.tzinfo:
self.now = self.get_local_tz().localize(self.now)
elif ptz:
_now = datetime.now(ptz)
if 'local' in _settings_tz:
self.now = _now
else:
self.now = apply_timezone(_now, settings.TIMEZONE)
else:
if 'local' not in _settings_tz:
utc_dt = datetime.utcnow()
self.now = apply_timezone(utc_dt, settings.TIMEZONE)
else:
self.now = datetime.now(self.get_local_tz())
date, period = self._parse_date(date_string)
if date:
date = apply_time(date, _time)
if settings.TO_TIMEZONE:
date = apply_timezone(date, settings.TO_TIMEZONE)
if (
else:
self.now = apply_timezone(_now, settings.TIMEZONE)
else:
if 'local' not in _settings_tz:
utc_dt = datetime.utcnow()
self.now = apply_timezone(utc_dt, settings.TIMEZONE)
else:
self.now = datetime.now(self.get_local_tz())
date, period = self._parse_date(date_string)
if date:
date = apply_time(date, _time)
if settings.TO_TIMEZONE:
date = apply_timezone(date, settings.TO_TIMEZONE)
if (
not settings.RETURN_AS_TIMEZONE_AWARE or
(settings.RETURN_AS_TIMEZONE_AWARE and
'default' == settings.RETURN_AS_TIMEZONE_AWARE and not ptz)
):
date = date.replace(tzinfo=None)
self.now = None
return date, period
date_string = six.text_type(date_string)
if not date_string.strip():
raise ValueError("Empty string")
date_string = strip_braces(date_string)
date_string, ptz = pop_tz_offset_from_string(date_string)
date_obj, period = parse(date_string, settings=settings)
_settings_tz = settings.TIMEZONE.lower()
if ptz:
date_obj = ptz.localize(date_obj)
if 'local' not in _settings_tz:
date_obj = apply_timezone(date_obj, settings.TIMEZONE)
else:
if 'local' in _settings_tz:
stz = get_localzone()
date_obj = stz.localize(date_obj)
else:
date_obj = localize_timezone(date_obj, settings.TIMEZONE)
if settings.TO_TIMEZONE:
date_obj = apply_timezone(date_obj, settings.TO_TIMEZONE)
if (
not settings.RETURN_AS_TIMEZONE_AWARE or
(settings.RETURN_AS_TIMEZONE_AWARE and
'default' == settings.RETURN_AS_TIMEZONE_AWARE and not ptz)
):
date_obj = date_obj.replace(tzinfo=None)
_settings_tz = settings.TIMEZONE.lower()
if ptz:
date_obj = ptz.localize(date_obj)
if 'local' not in _settings_tz:
date_obj = apply_timezone(date_obj, settings.TIMEZONE)
else:
if 'local' in _settings_tz:
stz = get_localzone()
date_obj = stz.localize(date_obj)
else:
date_obj = localize_timezone(date_obj, settings.TIMEZONE)
if settings.TO_TIMEZONE:
date_obj = apply_timezone(date_obj, settings.TO_TIMEZONE)
if (
not settings.RETURN_AS_TIMEZONE_AWARE or
(settings.RETURN_AS_TIMEZONE_AWARE and
'default' == settings.RETURN_AS_TIMEZONE_AWARE and not ptz)
):
date_obj = date_obj.replace(tzinfo=None)
return date_obj, period