Skip to content

fix: add missing 'd' (days) unit to parse_duration#65

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

fix: add missing 'd' (days) unit to parse_duration#65
XananasX7 wants to merge 1 commit into
tine1117:mainfrom
XananasX7:fix/parse-duration-days-unit

Conversation

@XananasX7

Copy link
Copy Markdown

Summary

Fixes #1parse_duration was silently dropping the d (days) unit.

Root Cause

The _TOKEN regex already accepted d as a valid unit character ([wdhms]), but the _UNITS mapping dict did not include "d". This meant day tokens were consumed (no ValueError raised) but contributed nothing to the total.

Fix

Added "d": 86400 to _UNITS, so:

parse_duration("1d")   # 86400  ✓
parse_duration("2d4h") # 187200 ✓

Also updated the leading comment in _UNITS to include "days" and added parse_duration("1d") -> 86400 to the docstring examples.

Tests Added

  • test_daysparse_duration("1d") == 86400
  • test_days_combinedparse_duration("2d4h") == 187200

All 9 tests pass.

The _UNITS dict accepted the 'd' character via the token regex but
never mapped it to a second value, so day-based durations silently
returned 0 instead of the correct number of seconds.

Fix: add 'd': 86400 to _UNITS so parse_duration('1d') == 86400
and parse_duration('2d4h') == 187200.

Tests: add test_days and test_days_combined to cover both cases.

Closes 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