-
Notifications
You must be signed in to change notification settings - Fork 71
feat: Support compound duration parsing in Duration.parse() #213
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
Merged
martinschaer
merged 7 commits into
surrealdb:main
from
dyleeeeeeee:feature/flexible-duration-parsing
Dec 1, 2025
Merged
feat: Support compound duration parsing in Duration.parse() #213
martinschaer
merged 7 commits into
surrealdb:main
from
dyleeeeeeee:feature/flexible-duration-parsing
Dec 1, 2025
Conversation
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
Enhance Duration.parse() to handle compound duration strings like \"1h30m\", \"2d3h15m\", etc., in addition to single-unit durations. - Modified parse() to use regex pattern matching - Added support for multiple units in a single duration string - Maintained backward compatibility with single-unit durations - Added comprehensive test coverage Resolves common use cases where users need to express durations with multiple units (e.g., \"1 hour and 30 minutes\" as \"1h30m\").
ssttuu
previously requested changes
Nov 12, 2025
2 tasks
The regex pattern in Duration.parse() includes 'µs' (microsecond with µ symbol) and 'y' (year) but they were missing from the UNITS dictionary, causing ValueError when parsing durations with these units. Added: - 'µs': microsecond (same as 'us') = 1e3 nanoseconds - 'y': year (365 days) = 31,536,000,000,000,000 nanoseconds Also added years property and updated to_string() to include years in the unit hierarchy.
- Replace simple compound test with comprehensive test using all units (1y2w3d4h5m6s7ms8us9ns) - Add individual tests for years (y) and microseconds with µ symbol (µs) - Update properties test to include years property - Add years to to_string test - Ensures complete coverage of newly added duration units
Merge separate tests into one that verifies both 'us' and 'µs' variants produce identical results, ensuring the µ symbol variant works correctly.
2 tasks
Collaborator
|
hi @dyleeeeeeee ! Can you run |
martinschaer
approved these changes
Dec 1, 2025
requested changes complete as per @martinschaer
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.
Description
Enhances
Duration.parse()to support compound duration strings like "1h30m", "2d3h15m", etc.Motivation
Currently,
Duration.parse()only supports single-unit durations ("2h", "30m").This limitation requires users to convert compound durations manually. For example,
"1 hour and 30 minutes" cannot be expressed as "1h30m" and must be converted to "90m".
Changes
Duration.parse()to use regex pattern matching for flexible parsingTesting
Examples