perf(duration): faster and stricter ParseDuration.#246
Merged
fredbi merged 1 commit intogo-openapi:masterfrom Apr 29, 2026
Merged
perf(duration): faster and stricter ParseDuration.#246fredbi merged 1 commit intogo-openapi:masterfrom
fredbi merged 1 commit intogo-openapi:masterfrom
Conversation
This PR replaces the previous combo using time.ParseDuration from the standard library and supplementing it with an extra regexp-based parsing. Performances ============= Parsing is now single-pass, without regexp: the parser is a modified copy of the one proposed by the standard library, with our additional units and aliases (e.g. "week", "day"). Behavior ============= The pre-existing tolerance for extra-blank space has been maintained. Standard library support for "dot-only" decimal part is now generalized (e.g. .25 weeks works). Lazy prefix-only match has been suppressed, and unit check is stricter with explicit plural forms: to "week" or "weeks" work, but "weekz" no longer matches. Duration with composite units work with all aliases and blank space tolerance (e.g. "2 minutes 45 seconds" works). Tests ============= Edge cases that used to be tested by the standard library only are now tested directly, since time.ParseDuration is no longer called. Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #246 +/- ##
==========================================
+ Coverage 86.13% 86.50% +0.37%
==========================================
Files 18 18
Lines 2401 2467 +66
==========================================
+ Hits 2068 2134 +66
Misses 230 230
Partials 103 103 ☔ View full report in Codecov by Sentry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR replaces the previous combo using time.ParseDuration from the standard library and supplementing it with an extra regexp-based parsing.
Performances
Parsing is now single-pass, without regexp: the parser is a modified copy of the one proposed by the standard library, with our additional units and aliases (e.g. "week", "day").
Behavior
The pre-existing tolerance for extra-blank space has been maintained.
Standard library support for "dot-only" decimal part is now generalized (e.g. .25 weeks works).
Lazy prefix-only match has been suppressed, and unit check is stricter with explicit plural forms: to "week" or "weeks" work, but "weekz" no longer matches.
Duration with composite units work with all aliases and blank space tolerance (e.g. "2 minutes 45 seconds" works).
Tests
Edge cases that used to be tested by the standard library only are now tested directly, since time.ParseDuration is no longer called.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist