scrapinghub / scrapinghub/dateparser
Bug Parsing Month/Day with %z in format
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 520
- Avg merge
- 22h 56m
- Merged PRs (30d)
- 6
Description
Two parter:
- Parsing a date string with a %z-formatted timezone in it causes the month and day to be reversed:
import dateparser
# Formats
abbreviatedFmt = '%Y-%m-%d %I:%M:%S.%f %p %Z'
extendedFmt = '{} (%z)'.format(abbreviatedFmt)
print('Formats:')
print(abbreviatedFmt)
print(extendedFmt)
# Input datetime strings
abbreviatedDateStr = "2012-11-02 04:16:13.000123 PM EST"
extendedDateStr = '{} (-05:00)'.format(abbreviatedDateStr)
print('Input datetime strings:')
print(abbreviatedDateStr)
print(extendedDateStr)
# Output datetime strings
print('Output datetime strings:')
print(dateparser.parse(abbreviatedDateStr, date_formats = [abbreviatedFmt]).strftime(abbreviatedFmt))
print(dateparser.parse(extendedDateStr, date_formats = [extendedFmt]).strftime(extendedFmt))
Formats:
%Y-%m-%d %I:%M:%S.%f %p %Z
%Y-%m-%d %I:%M:%S.%f %p %Z (%z)
Input datetime strings:
2012-11-02 04:16:13.000123 PM EST
2012-11-02 04:16:13.000123 PM EST (-05:00)
Output datetime strings:
2012-11-02 04:16:13.000123 PM EST
2012-02-11 04:16:13.000123 PM UTC-05:00 (-0500)
As can be seen above the resulting (output) datetime string for the one with extended %z formatting has its month and day reversed.
- Additionally as can be seen above, it also overrides the name of the timezone if one has been provided, even if the timezone offsets match.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reproduction script from the issue with both date_formats values and compare the parsed and formatted results. Trace the parsing path for the %z format alongside %Z. Done means the extended input preserves month/day order and does not replace a supplied timezone name when the offsets match.
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
- Mostly clear
- Newbie friendliness
- 35/100