Skip to content

Conversation

@TheElectronWill
Copy link
Contributor

@TheElectronWill TheElectronWill commented Aug 14, 2025

This PR implements the support of fractional durations such as 1.5h and 3.2s 0.456us.

It does not add any dependency: the parser stays minimal.
Resolves #34.

About Precision

To avoid precision loss, the new function parse_fractional_part does not rely on floats, but parses 0.123 as a decimal fraction 123/1000. This fraction is then added to the duration's value, depending on the unit. Any loss of precision or overflow during the computations is reported as an error, avoiding float problems. u64::MAX is about 1.8×10¹⁹, so it supports plenty of decimal places and a large range of units.

The minimum granularity is 1 nanosecond. For example, the following inputs are rejected: 0.5ns, 31.0000001ms.

@djc
Copy link
Member

djc commented Aug 14, 2025

I took care of the reformatting changes to make sure they don't end up in this PR. Please rebase on main.

@TheElectronWill
Copy link
Contributor Author

TheElectronWill commented Aug 15, 2025

rebased :)
Should I bump the crate's version number or do you want to do it?

@TheElectronWill
Copy link
Contributor Author

I've fixed clippy's remark.

@djc djc merged commit 9383ae2 into chronotope:main Sep 11, 2025
7 checks passed
@djc
Copy link
Member

djc commented Sep 11, 2025

Thanks!

@djc djc mentioned this pull request Sep 11, 2025
9999years added a commit to MercuryTechnologies/ghciwatch that referenced this pull request Sep 11, 2025
This allows usage like `ghciwatch --debounce 0.1s`. Previously, decimals
were not supported, so you had to do (e.g.) `--debounce 100ms`, which
was not very intuitive.

See: chronotope/humantime#56
9999years added a commit to MercuryTechnologies/ghciwatch that referenced this pull request Sep 11, 2025
This allows usage like `ghciwatch --debounce 0.1s`. Previously, decimals
were not supported, so you had to do (e.g.) `--debounce 100ms`, which
was not very intuitive.

See: chronotope/humantime#56
kodiakhq bot pushed a commit to pdylanross/fatigue that referenced this pull request Sep 12, 2025
Bumps humantime from 2.2.0 to 2.3.0.

Release notes
Sourced from humantime's releases.

2.3.0
What's Changed

Add 'wk', 'wks' for weeks and 'yr', 'yrs' for years by @​ryo1kato in chronotope/humantime#50
Allow parsing zero durations with no units by @​RobertGauld in chronotope/humantime#43
Use µs not us by @​RobertGauld in chronotope/humantime#45
feat: parse_duration("0") by @​aatifsyed in chronotope/humantime#55
Support fractional durations (with precision safeguards, without any new dependency) by @​TheElectronWill in chronotope/humantime#56
feat: Accept "+00:00" as an alternative way to specify the UTC timezone by @​TheElectronWill in chronotope/humantime#59
Fractional tweaks by @​djc in chronotope/humantime#60




Commits

7994b71 ci: disable for non-main pushes
1b59068 Bump version to 2.3.0
cacdb93 ci: add audit job
5cc8dc5 ci: add job to check semver compatibility
0d5fe2d Bump version to 2.2.1
fc0e7ea duration: move current value out of Parser
1febd52 duration: track current value as Duration
0adba12 duration: track current nanoseconds as u32
786218f Extract unit parsing
9ff48bf Re-order duration parser methods in top-down order
Additional commits viewable in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot merge will merge this PR after your CI passes on it
@dependabot squash and merge will squash and merge this PR after your CI passes on it
@dependabot cancel merge will cancel a previously requested merge and block automerging
@dependabot reopen will reopen this PR if it is closed
@dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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.

Support fractional durations

2 participants