Skip to content

fix(nb): improve Norwegian Bokmål date parsing - #1334

Merged
AdrianAtZyte merged 4 commits into
scrapinghub:masterfrom
terhoy:improve-norwegian-dates
Jun 5, 2026
Merged

AdrianAtZyte merged 4 commits into
scrapinghub:masterfrom
terhoy:improve-norwegian-dates

Conversation

@terhoy

@terhoy terhoy commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Improves Norwegian Bokmål (nb) date parsing support by updating
supplementary language data and regenerating nb.py.

Changes

  • Add plural forms for time units (måneder, uker, dager, timer, minutter, sekunder)
  • Add weekday abbreviations (man, tir, ons, tor, fre, lør, søn)
  • Add noon/midnight translations (middag, midnatt)
  • Add kl/kl. to skip list to support 'dato kl 14:30' format
  • Add simplifications for Norwegian number words (en, to, tre...)
  • Remove duplicate entries already present in CLDR data
  • Regenerate nb.py via write_complete_data.py

Test results

All 20 test cases pass:

  • Relative dates: "3 måneder siden", "2 uker siden", "om 3 uker"
  • Date + time: "15. mars 2025 kl 14:30"
  • Weekday abbreviations: "man", "tir", "ons", "tor", "fre", "lør", "søn"
  • Month names and abbreviations
  • Number word simplifications: "en", "to", "tre" etc.

Notes

tox could not be run locally — atheris does not support Windows.
CI will run the full test suite on Linux.

- Add plural forms for time units (måneder, uker, dager, timer, minutter, sekunder)
- Add weekday abbreviations (man, tir, ons, tor, fre, lør, søn)
- Add noon/midnight translations (middag, midnatt)
- Add kl/kl. to skip list to support 'dato kl 14:30' format
- Add simplifications for Norwegian number words (en, to, tre...)
- Remove duplicate entries already present in CLDR data
- Regenerate nb.py via write_complete_data.py
@AdrianAtZyte

Copy link
Copy Markdown
Member

Besides cleaning the changes, please extend tests to cover at least some of the new scenarios. And make sure to run the tests locally to verify that the changes do not (unintentionally) break pre-existing tests.

Changes to nb.yaml:
- Keep only data not already present in CLDR
- Add plural time units: måneder, uker, dager, timer, minutter, sekunder
- Add relative-type-regex only for 'dager siden' (missing in CLDR)
- Add ago/in translations: siden, om
- Add noon/midnight: middag, midnatt
- Add skip tokens: kl, kl. (enables parsing of 'dato kl 14:30')
- Add simplifications for Norwegian number words: en, to, tre...
- Remove all entries duplicated from CLDR (weekday abbr., month abbr., regex)

nb.py regenerated via dateparser_scripts/write_complete_data.py.
Verified with custom duplicate checker: no duplicates in any category.

Tests added to tests/test_languages.py:
- 3 måneder siden -> 3 month ago
- 2 dager siden -> 2 day ago
- 5 uker siden -> 5 week ago
- 30 minutter siden -> 30 minute ago
- 45 sekunder siden -> 45 second ago
- om 3 uker -> in 3 week
- om 2 måneder -> in 2 month

All 19 nb tests pass locally. Pre-existing tests unaffected.
@AdrianAtZyte AdrianAtZyte reopened this Jun 5, 2026
@AdrianAtZyte

Copy link
Copy Markdown
Member

(closed and reopened so that CI would pick up 333e519, which I have just merged)

@codecov

codecov Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.11%. Comparing base (5c437a1) to head (8c23166).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1334   +/-   ##
=======================================
  Coverage   97.11%   97.11%           
=======================================
  Files         235      235           
  Lines        2912     2912           
=======================================
  Hits         2828     2828           
  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.

Remove 'noon' (middag) and 'midnight' (midnatt) from nb.yaml as
these are not supported by the current dateparser infrastructure
without additional code changes. A separate PR can be created if/
when code support for noon/midnight translations is added.
@AdrianAtZyte
AdrianAtZyte merged commit 081d251 into scrapinghub:master Jun 5, 2026
15 checks passed
@AdrianAtZyte

Copy link
Copy Markdown
Member

Thanks!

@terhoy
terhoy deleted the improve-norwegian-dates branch June 5, 2026 11:05
@serhii73 serhii73 mentioned this pull request Jun 15, 2026
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.

2 participants