-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Bug]: Date Parsing Fails for Certain Formats #8
Comments
QA: Example: parse_date("2024/11/21") Raises: ValueError: time data '2024/11/21' does not match format '%Y-%m-%d' Can we add support for additional formats or implement a way to dynamically detect the date format? |
Developer:
I’ll also improve the error message for unsupported formats. Let me work on a fix. |
Developer: Dynamic Format Detection: Integrated dateutil.parser.parse for automatic detection of common date formats. Updated function: from dateutil.parser import parse
def parse_date(date_str, format=None):
try:
return parse(date_str) if not format else datetime.strptime(date_str, format)
except ValueError as e:
raise ValueError(f"Unsupported date format: {date_str}. Please use a valid format.") from e The changes are now in branch fix/date-parsing. Please test and let me know. |
QA: Dynamic Parsing: Handled YYYY/MM/DD, DD-MM-YYYY, and MM/DD/YYYY without issues. |
Developer: |
The parse_date() function fails to correctly handle dates in certain formats, specifically YYYY/MM/DD. While the function supports YYYY-MM-DD and MM-DD-YYYY, any deviation leads to a ValueError.
Reproduction Steps:
Actual Output: Raises ValueError: time data '2024/11/21' does not match format '%Y-%m-%d'.
Expected Output: Return a valid datetime.date object for the input date.
Actual Output: Same ValueError.
Expected Output: Automatically detect the format and parse the date correctly.
Suspected Cause:
The function only supports hardcoded formats (%Y-%m-%d and %m-%d-%Y), and there’s no mechanism to dynamically detect other common date formats.
Impact:
This bug prevents the function from handling date inputs from diverse sources (e.g., APIs, user inputs, or files), limiting its usability in real-world applications.
Expected Behavior:
The text was updated successfully, but these errors were encountered: