How to use the dateparser.utils.localize_timezone function in dateparser

To help you get started, we’ve selected a few dateparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scrapinghub / dateparser / tests / test_utils.py View on Github external
def test_localize_timezone_function(self, date, timezone, zone):
        tzaware_dt = localize_timezone(date, timezone)
        self.assertEqual(tzaware_dt.tzinfo.zone, zone)
github scrapinghub / dateparser / tests / test_utils.py View on Github external
def test_localize_timezone_function_exception(self, date, timezone, zone):
        tzaware_dt = localize_timezone(date, timezone)
        self.assertEqual(tzaware_dt.tzinfo._StaticTzInfo__name, zone)
github scrapinghub / dateparser / dateparser / date_parser.py View on Github external
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)

        return date_obj, period
github scrapinghub / dateparser / dateparser / freshness_date_parser.py View on Github external
_settings_tz = settings.TIMEZONE.lower()

        def apply_time(dateobj, timeobj):
            if not isinstance(_time, time):
                return dateobj

            return dateobj.replace(
                hour=timeobj.hour, minute=timeobj.minute,
                second=timeobj.second, microsecond=timeobj.microsecond
            )

        if settings.RELATIVE_BASE:
            self.now = settings.RELATIVE_BASE

            if 'local' not in _settings_tz:
                self.now = localize_timezone(self.now, settings.TIMEZONE)

            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: