kennethreitz / maya

Datetimes for Humans™
MIT License
3.41k stars 199 forks source link

Invalid date format - %Y\%m\%d #200

Open FluffyDietEngine opened 8 months ago

FluffyDietEngine commented 8 months ago

Bug description - I am getting the below traceback when I tried to parse the following date from one of the documents I am working on. -> "2023\09\11"

Traceback

Traceback (most recent call last):
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/dateutil/parser/_parser.py", line 649, in parse
    ret = self._build_naive(res, default)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/dateutil/parser/_parser.py", line 1235, in _build_naive
    naive = default.replace(**repl)
            ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: year 20239 is out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 131, in _parse
    dt = parser.parse(
         ^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/dateutil/parser/_parser.py", line 651, in parse
    six.raise_from(ParserError(str(e) + ": %s", timestr), e)
  File "<string>", line 3, in raise_from
dateutil.parser._parser.ParserError: year 20239 is out of range: 20239

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/santhoshsolomon/Projects/async-scraper/prefect_module/test.py", line 5, in <module>
    parse(date_1)
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/maya/core.py", line 766, in parse
    dt = pendulum.parse(str(string), **options)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parser.py", line 29, in parse
    return _parse(text, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parser.py", line 45, in _parse
    parsed = base_parse(text, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 74, in parse
    return _normalize(_parse(text, **_options), **_options)
                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 135, in _parse
    raise ParserError("Invalid date string: {}".format(text))
pendulum.parsing.exceptions.ParserError: Invalid date string: 20239

While reading the traceback I have understood the issue is due to the escape string character \ and I have modified the date like "2023\09\11". Now the issue is something different, traceback as follows,

Traceback (most recent call last):
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 131, in _parse
    dt = parser.parse(
         ^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/dateutil/parser/_parser.py", line 643, in parse
    raise ParserError("Unknown string format: %s", timestr)
dateutil.parser._parser.ParserError: Unknown string format: 2023\09\11

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/santhoshsolomon/Projects/async-scraper/prefect_module/test.py", line 5, in <module>
    parse(date_1)
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/maya/core.py", line 766, in parse
    dt = pendulum.parse(str(string), **options)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parser.py", line 29, in parse
    return _parse(text, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parser.py", line 45, in _parse
    parsed = base_parse(text, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 74, in parse
    return _normalize(_parse(text, **_options), **_options)
                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Projects/mr_hulk/venv/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 135, in _parse
    raise ParserError("Invalid date string: {}".format(text))
pendulum.parsing.exceptions.ParserError: Invalid date string: 2023\09\11

I am interested in knowing what is going wrong here.

Environment and Version