Skip to content

Formats passed in date_formats only work for English, even if languages=["es"] #433

Closed

Description

@alvaroabascar
  • version: 0.7.0

Apparently, months, weekdays etc. are not captured if they are specified in a custom format passed in date_formats unless they are written in English, independently from the languages you pass under languages. I add an example below.

dateparser.parse('xxxx junio', languages=['es'], date_formats=['xxxx %B'])
# >> None
dateparser.parse('xxxx june', languages=['es'], date_formats=['xxxx %B'])
# >> datetime.datetime(2018, 6, 30, 0, 0)

Activity

  1. noviluni commented on Nov 23, 2020

    @noviluni
    Contributor

    This is not exactly true. The date_formats depends on the locale set on the computer. If the locale is 'es' this shouldn't happen.

    You can usually change the locale by doing this (it works for me on Ubuntu):

    >>> import locale
    >>> locale.setlocale(locale.LC_ALL, 'es_ES.UTF-8')
    'es_ES.UTF-8'
    

    Now this will work:

    >>> dateparser.parse('xxxx junio', date_formats=['xxxx %B'])
    datetime.datetime(2020, 6, 23, 0, 0)
    

    I tried to figure out if we could internally change the locale and try the format in multiple locales, but I think changing the locale is discouraged and could cause other issues...

    I will check this again in the future.

  2. Gallaecio commented on Nov 23, 2020

    @Gallaecio
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions