Skip to content

Add 'w' as an English abbreviation for 'week' (#1257) - #1349

Open
apoorvdarshan wants to merge 1 commit into
scrapinghub:masterfrom
apoorvdarshan:add-w-week-abbreviation-1257
Open

Add 'w' as an English abbreviation for 'week' (#1257)#1349
apoorvdarshan wants to merge 1 commit into
scrapinghub:masterfrom
apoorvdarshan:add-w-week-abbreviation-1257

Conversation

@apoorvdarshan

Copy link
Copy Markdown

Fixes #1257.

Problem

"1w ago" returns None, even though the full word and every other single-letter unit abbreviation work:

>>> dateparser.parse("1w ago")     # None
>>> dateparser.parse("1week ago")  # works
>>> dateparser.parse("1d ago")     # works (day)
>>> dateparser.parse("1h ago")     # works (hour)
>>> dateparser.parse("1m ago")     # works (minute)
>>> dateparser.parse("1s ago")     # works (second)
>>> dateparser.parse("1y ago")     # works (year)

Every relative-time unit had a single-letter abbreviation except week: in the English translation data, day has d, hour has h, minute has m, second has s, year has y, but week only had week/wk/weeks.

Fix

Add w to the English week translation data in dateparser_data/supplementary_language_data/date_translation_data/en.yaml and regenerate dateparser/data/date_translation_data/en.py with dateparser_scripts/write_complete_data.py.

month intentionally keeps no single-letter form (since m already means minute), but w is unambiguous, so this fills a genuine gap rather than introducing a conflict.

>>> dateparser.parse("1w ago")   # 7 days ago
>>> dateparser.parse("2w ago")   # 14 days ago
>>> dateparser.parse("in 2w")    # 14 days in the future

Testing

  • Added "1w ago" / "2w ago" cases to tests/test_freshness_date_parser.py (next to the existing "2y ago" abbreviation case). They fail on main and pass with this change.
  • Full tests/test_freshness_date_parser.py (1057) and tests/test_search.py (244) pass — no regressions.
  • ruff check / ruff format --check clean on the changed files.

Disclosure: this change was prepared with the assistance of an AI tool (Claude Code). I reproduced the issue, made the data change and regenerated en.py with the project's own script, verified the fix and the test run, and take responsibility for the contribution and will respond to review feedback personally.

'1w ago' returned None while '1d', '1h', '1m', '1s' and '1y' all worked:
every relative-time unit had a single-letter abbreviation except week.

Add 'w' to the English 'week' translation data and regenerate en.py.
'month' intentionally keeps no single-letter form ('m' is minute), but
'w' is unambiguous. Adds freshness parser tests for '1w ago'/'2w ago'.
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.11%. Comparing base (273eb23) to head (f0f1113).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1349   +/-   ##
=======================================
  Coverage   97.11%   97.11%           
=======================================
  Files         235      235           
  Lines        2910     2910           
=======================================
  Hits         2826     2826           
  Misses         84       84           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Successfully merging this pull request may close these issues.

"1w ago" not supported

2 participants