Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMM is not case-insensitive like Java #809

Open
saorav21994 opened this issue Feb 25, 2024 · 0 comments
Open

MMM is not case-insensitive like Java #809

saorav21994 opened this issue Feb 25, 2024 · 0 comments

Comments

@saorav21994
Copy link

  • [Y] I have searched the issues of this repo and believe that this is not a duplicate.
  • [Y] I have searched the documentation and believe that my question is not covered.

Feature Request

I came across a weird discrepancy in pendulum compared to other language supports.
MMM does not consider case-insensitivity.
Ex. -
25-Feb-2024 is correct recognizable, however, 25-feb-2024 is not. This is because months.abbreviated for MMM only corresponds to "Feb" for february.
If we consider other language like Java, this is natively supported.

import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.util.Date;
class HelloWorld {
    public static void main(String[] args) {
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MMMM-yyyy");
        String dateStr = "23-FeB-2024";
        Date date = null;
        
        try {
            date = formatter.parse(dateStr);
            System.out.println(date);
        } catch (Exception exception) {
            System.out.println("Could not parse ... " + exception);
        }
    }
}

Output:
Fri Feb 23 00:00:00 GMT 2024

For pendulum --

import pendulum
file_date = pendulum.from_format("23-feb-2024", "DD-MMM-YYYY")
print(date_from_text)

Output:

Traceback (most recent call last):
  File "/~/pend.py", line 10, in <module>
    file_date = pendulum.from_format("23-feb-2024", "DD-MMM-YYYY")
  File "/~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/pendulum/__init__.py", line 284, in from_format
    parts = _formatter.parse(string, fmt, now(tz=tz), locale=locale)
  File "/~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/pendulum/formatting/formatter.py", line 409, in parse
    raise ValueError(f"String does not match format {fmt}")
ValueError: String does not match format DD-MMM-YYYY

I made some changes but was unable to push to remote repository due it lack of permissions.

Changes:

Inside _get_parsed_locale_value function in file formatter.py on line 630
make,
value = value.lower()

In files - src/pendulum/locales/<en, en_gb, en_us>/locale.py --> make , all MMM month to lower case for months.abbreviated.

I believe the above changes should tackle this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant