Repository navigation
feat(runtime): extend the duration system package - #2265
Merged
Merged
Conversation
Add the parsing, formatting, and conversion APIs that make the duration module useful alongside datetime. Compact durations now accept Go subsecond units, fixed-length ISO 8601 values parse and format, and callers can convert, scale, compare, and shift the datetimes the datetime package already produces. Native + and - on durations stay out of scope. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Peefy <Peefy@users.noreply.github.com>
The new duration functions shift later builtin symbol indexes by 10. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Peefy <Peefy@users.noreply.github.com>
Each new duration builtin adds one node, symbol, and fully qualified name. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Peefy <Peefy@users.noreply.github.com>
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.
Summary
Related to #1907. This does not close the issue. #2192 landed the first
durationmodule (constructors,parse/is_valid,to_seconds/from_seconds,add/sub, and RFC 3339 shifts). The example in the issue still usesduration + durationanddatetime + duration. That operator work was left open in the #1907 discussion, and this change does not add it.This slice makes the module usable for the configuration cases in the issue, in the same function style as
datetime:500ms,250us,1µs,100ns). Fixed-length ISO 8601 durations parse too (PT1H30M,P1DT2H,P1W). Years and months are rejected because they are not a fixed length. Output stays the existing compact form (1h30m,0.5s).to_iso8601renders a normalized ISO 8601 duration (PT1H30M,P1DT2H3M4S,PT0S). Weeks are emitted as days.millisecond,to_milliseconds,to_minutes,to_hours, andto_dayssit next to the existing second-based helpers.mul,div, andcmp. String order is not duration order (cmp("2h", "30m")is1).add_to_datetimeandsub_from_datetimeaccept RFC 3339 and the strings produced bydatetime.today(),datetime.date(), anddatetime.now()with its default format.between(start, end)is the inverse. Results are still RFC 3339.The issue example, without
+:kcl.hnow declareskcl_duration_is_validas returningkcl_value_ref_t*, matching the other builtins. The Rust function already returned a value reference.Out of scope
+/-on duration strings, or ondatetimevalues. No compiler hook for that was decided in Support duration/interval type in the system package #1907.Durationschema.datetimeis also a set of functions over strings.Tests
cargo test -p kcl-runtime --lib duration::— 17 passedtests/grammar/builtins/duration— 16 passed, including the previous cases and the new parse, convert, scale, and datetime-shift fixtures