Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow durations without leading 0s in the hour #74

Merged
merged 5 commits into from
Oct 21, 2024

Conversation

mrob95
Copy link
Contributor

@mrob95 mrob95 commented Oct 12, 2024

Fixes pydantic/pydantic#8248

Supports the following formats:

>>> str(timedelta(hours=3))
'3:00:00'
>>> str(timedelta(minutes=3))
'0:03:00'
>>> str(timedelta(minutes=3, seconds=1))
'0:03:01'
>>> str(timedelta(days=3, hours=9, minutes=5, seconds=10))
'3 days, 9:05:10'

Note that this is technically a breaking change due to the change in error type when there are characters left over after parsing a duration, from InvalidCharTzSign to ExtraCharacters. I think this makes more sense as there is no such thing as a valid timezone for a duration.

I started down the road of trying to unify the time parsing between durations and times using PureTime, but it became a bit of a mess, requiring breaking changes to PureTime (e.g. PureTime stores hours as a u8 currently, but duration parsing needs at least u32).

Copy link

codecov bot commented Oct 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.87%. Comparing base (0ffbcbb) to head (289c653).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
- Coverage   99.12%   98.87%   -0.26%     
==========================================
  Files           6        6              
  Lines         917      975      +58     
==========================================
+ Hits          909      964      +55     
- Misses          8       11       +3     
Files with missing lines Coverage Δ
src/duration.rs 99.04% <100.00%> (-0.96%) ⬇️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d15ac62...289c653. Read the comment docs.

@mrob95
Copy link
Contributor Author

mrob95 commented Oct 13, 2024

The CI pre-commit stage was failing trying to install pre-commit outside of a virtual environment. I copied the setup-python step from https://github.com/pydantic/pydantic-core/blob/main/.github/workflows/ci.yml#L265C1-L267C33 to fix.

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think the change in error message is probably positive 👍

@davidhewitt davidhewitt merged commit 680566a into pydantic:main Oct 21, 2024
7 checks passed
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.

Can no longer parse str() of timedelta
2 participants