Parsing date from file path
- Dominant language
- Python
- Stars
- 9.1k
- Forks
- 784
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
Hello!
I'm trying to parse date from file path and facing an issue:
```
arrow.get("/absolute/path/2020-12-16/16-55-22/file.txt", "YYYY-MM-DD/hh-mm-ss")
```
Gives
```
Traceback (most recent call last):
File ".../scratches/scratch_64.py", line 10, in
print(arrow.get("/absolute/path/2020-12-16/16-55-22/file.txt", "YYYY-MM-DD/hh-mm-ss"))
File ".../.pyenv/versions/3.8.5/lib/python3.8/site-packages/arrow/api.py", line 91, in get
return _factory.get(*args, **kwargs)
File ".../versions/3.8.5/lib/python3.8/site-packages/arrow/factory.py", line 292, in get
dt = parser.DateTimeParser(locale).parse(
File ".../.pyenv/versions/3.8.5/lib/python3.8/site-packages/arrow/parser.py", line 326, in parse
raise ParserMatchError(
arrow.parser.ParserMatchError: Failed to match 'YYYY-MM-DD/hh-mm-ss' when parsing '/absolute/path/2020-12-16/16-55-22/file.txt'.
```
This workaround works fine:
```
arrow.get("/absolute/path/2020-12-16/16-55-22/file.txt".replace("/", " "), "YYYY-MM-DD hh-mm-ss")
```
But if path gets little more complicated it fails again:
```
arrow.get("/absolute/path/prefix-2020-12-16/16-55-22/file.txt".replace("/", " "), "YYYY-MM-DD hh-mm-ss")
```
## System Info
- 🖥 **OS name and version**: macOS 10.15.7
- 🐍 **Python version**: Python 3.8.5
- 🏹 **Arrow version**: 1.1.1
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the issue with arrow.get and inspect the parser.DateTimeParser.parse entry point named in the traceback. Compare the direct path and workaround examples, then define the intended matching behavior for both paths and verify it with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100