Skip to content

fix: add days ("d") unit to parse_duration#55

Open
NONONO3199 wants to merge 1 commit into
tine1117:mainfrom
NONONO3199:fix/parse-duration-days
Open

fix: add days ("d") unit to parse_duration#55
NONONO3199 wants to merge 1 commit into
tine1117:mainfrom
NONONO3199:fix/parse-duration-days

Conversation

@NONONO3199

Copy link
Copy Markdown

Problem

The parse_duration function accepts "d" as valid input (the regex matches it), but silently ignores the day value because _UNITS is missing the "d" key.

  • parse_duration("1d") returns 0 instead of 86400
  • parse_duration("2d4h") returns 14400 instead of 187200

Fix

  • Added "d": 86400 to the _UNS dict in duration_utils.py
  • Added test_days and test_days_combined test cases

Tests

All 9 tests pass:

test_combined ... ok
test_days ... ok
test_days_combined ... ok
test_empty_raises ... ok
test_hours ... ok
test_invalid_raises ... ok
test_minutes ... ok
test_seconds ... ok
test_weeks ... ok

Fixes #1

The _TOKEN regex already accepted "d" but _UNITS was missing
the "d" key, causing day values to be silently ignored.

- Add "d": 86400 to _UNS dict
- Add test_days and test_days_combined test cases
- Update docstring with day example

Fixes tine1117#1
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.

parse_duration drops the days (d) unit

1 participant