Skip to content

babel.dates.parse_date() doesn't allow you to specify a format/pattern #432

@johanndt

Description

@johanndt

We've started using Babel recently but ran into an issue where babel.dates.parse_date() doesn't allow us to specify the format to use. It always uses the 'medium' format. And for some formats that fails. Eg. when using 'en_ZA', you can't parse a short format date.

Internally the first thing it does is call get_date_format() without being explicit about the format, thus the default 'medium' format always gets used.

I'm happy to submit a pull-request but need some guidance on what type of fix would be acceptable.
To stick with the signature order used everywhere else would require a change to parse_date(string, format='medium', locale=LC_TIME) but this would break people's code who were using only 2 positional arguments.

Can we add it at the end eg. parse_date(string, locale=LC_TIME, format='medium')?

Or should we create a new function eg: parse_formatted_date(string, format='medium', locale=LC_TIME)? The existing function name can then just be a wrapper around the new function.

Hope all this made sense. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions