How to use the dateparser.utils.apply_timezone_from_settings 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_apply_timezone_from_settings_function_should_return_tz(self, date):
        result = apply_timezone_from_settings(date, settings.replace(**{'RETURN_AS_TIMEZONE_AWARE': True}))
        self.assertTrue(bool(result.tzinfo))
github scrapinghub / dateparser / tests / test_utils.py View on Github external
def test_apply_timezone_from_settings_function(self, date, timezone, expected):
        result = apply_timezone_from_settings(date, settings.replace(**{'TO_TIMEZONE': timezone, 'TIMEZONE': 'UTC'}))
        self.assertEqual(expected, result)
github scrapinghub / dateparser / tests / test_utils.py View on Github external
def test_apply_timezone_from_settings_function_none_settings(self, date, expected):
        result = apply_timezone_from_settings(date, None)
        self.assertEqual(expected, result)
github scrapinghub / dateparser / dateparser / date.py View on Github external
date_obj = datetime.strptime(date_string, date_format)
        except ValueError:
            continue
        else:
            # If format does not include the day, use last day of the month
            # instead of first, because the first is usually out of range.
            if '%d' not in date_format:
                period = 'month'
                date_obj = date_obj.replace(
                    day=get_last_day_of_month(date_obj.year, date_obj.month))

            if not ('%y' in date_format or '%Y' in date_format):
                today = datetime.today()
                date_obj = date_obj.replace(year=today.year)

            date_obj = apply_timezone_from_settings(date_obj, settings)

            return {'date_obj': date_obj, 'period': period}
    else:
        return {'date_obj': None, 'period': period}
github scrapinghub / dateparser / dateparser / date.py View on Github external
def get_date_from_timestamp(date_string, settings):
    if RE_SEARCH_TIMESTAMP.search(date_string):
        date_obj = datetime.fromtimestamp(int(date_string[:10]))
        date_obj = apply_timezone_from_settings(date_obj, settings)
        return date_obj