Skip to content

feat(runtime): extend the duration system package - #2265

Merged
Peefy merged 3 commits into
mainfrom
cursor/duration-stdlib-apis-e19c
Nov 19, 2026
Merged

Peefy merged 3 commits into
mainfrom
cursor/duration-stdlib-apis-e19c

Conversation

@Peefy

@Peefy Peefy commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Related to #1907. This does not close the issue. #2192 landed the first duration module (constructors, parse / is_valid, to_seconds / from_seconds, add / sub, and RFC 3339 shifts). The example in the issue still uses duration + duration and datetime + 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:

  • Parsing. Compact form also accepts Go subsecond units (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).
  • Formatting. to_iso8601 renders a normalized ISO 8601 duration (PT1H30M, P1DT2H3M4S, PT0S). Weeks are emitted as days.
  • Conversion. millisecond, to_milliseconds, to_minutes, to_hours, and to_days sit next to the existing second-based helpers.
  • Arithmetic. mul, div, and cmp. String order is not duration order (cmp("2h", "30m") is 1).
  • Datetime. add_to_datetime and sub_from_datetime accept RFC 3339 and the strings produced by datetime.today(), datetime.date(), and datetime.now() with its default format. between(start, end) is the inverse. Results are still RFC 3339.

The issue example, without +:

import datetime
import duration

start = datetime.today()
length = duration.add(duration.minute(10), duration.minute(30))
end = duration.add_to_datetime(start, length)

kcl.h now declares kcl_duration_is_valid as returning kcl_value_ref_t*, matching the other builtins. The Rust function already returned a value reference.

Out of scope

Tests

  • cargo test -p kcl-runtime --lib duration:: — 17 passed
  • Grammar suite tests/grammar/builtins/duration — 16 passed, including the previous cases and the new parse, convert, scale, and datetime-shift fixtures
Open in Web Open in Cursor 

cursoragent and others added 3 commits November 17, 2026 12:32
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>
@Peefy
Peefy merged commit 791cd07 into main Nov 19, 2026
9 checks passed
@Peefy
Peefy deleted the cursor/duration-stdlib-apis-e19c branch November 19, 2026 04:29
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.

2 participants