How to use dateparser - 10 common examples

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 china-testing / python-api-tesing / flask / flask_web_service / Chapter08 / crimemap.py View on Github external
def format_date(userdate):
    date = dateparser.parse(userdate)
    try:
        return datetime.datetime.strftime(date, "%Y-%m-%d")
    except TypeError:
        return None
github scrapinghub / dateparser / tests / test_date.py View on Github external
def when_parser_is_initialized(self, languages=None, locales=None, region=None,
                                   try_previous_locales=True, use_given_order=False):
        try:
            self.parser = date.DateDataParser(
                languages=languages, locales=locales, region=region,
                try_previous_locales=try_previous_locales, use_given_order=use_given_order)
        except Exception as error:
            self.error = error
github scrapinghub / dateparser / tests / test_date_parser.py View on Github external
def given_parser(self, *args, **kwds):
        def collecting_get_date_data(parse):
            @wraps(parse)
            def wrapped(*args, **kwargs):
                self.date_result = parse(*args, **kwargs)
                return self.date_result
            return wrapped

        self.add_patch(patch.object(date_parser,
                                    'parse',
                                    collecting_get_date_data(date_parser.parse)))

        self.date_parser = Mock(wraps=date_parser)
        self.add_patch(patch('dateparser.date.date_parser', new=self.date_parser))
        self.parser = DateDataParser(*args, **kwds)
github scrapinghub / dateparser / tests / test_date.py View on Github external
def given_parser(self, restrict_to_languages=None, **params):
        self.parser = date.DateDataParser(languages=restrict_to_languages, **params)
github scrapinghub / dateparser / tests / test_languages.py View on Github external
def given_string(self, datetime_string):
        if self.settings.NORMALIZE:
            datetime_string = normalize_unicode(datetime_string)
        self.datetime_string = datetime_string
github scrapinghub / dateparser / tests / test_freshness_date_parser.py View on Github external
def test_normalized_relative_dates(self, date_string, ago, period):
        date_string = normalize_unicode(date_string)
        self.given_parser(settings={'NORMALIZE': True})
        self.given_date_string(date_string)
        self.when_date_is_parsed()
        self.then_error_was_not_raised()
        self.then_date_was_parsed_by_freshness_parser()
        self.then_date_obj_is_exactly_this_time_ago(ago)
        self.then_period_is(period)
github scrapinghub / dateparser / tests / test_languages.py View on Github external
def given_locales(self, *shortnames):
        self.known_languages = [default_loader.get_locale(shortname)
                                for shortname in shortnames]
github scrapinghub / dateparser / tests / test_languages.py View on Github external
def given_bundled_language(self, shortname):
        self.language = default_loader.get_locale(shortname)
github scrapinghub / dateparser / tests / test_languages.py View on Github external
def given_known_languages(self, shortnames):
        self.known_languages = [default_loader.get_locale(shortname)
                                for shortname in shortnames]
github scrapinghub / dateparser / tests / test_settings.py View on Github external
def test_apply_settings_should_return_default_settings_when_no_settings_are_supplied_to_the_decorated_function(self):
        test_func = apply_settings(test_function)
        self.assertEqual(test_func(), self.default_settings)