Skip to content

Math ops for baml.time.* - #4366

Merged
2kai2kai2 merged 2 commits into
canaryfrom
kai/stdlib
Aug 12, 2026
Merged

Math ops for baml.time.*#4366
2kai2kai2 merged 2 commits into
canaryfrom
kai/stdlib

Conversation

@2kai2kai2

@2kai2kai2 2kai2kai2 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor
  • Adding and subtracting Duration from time quantities
  • Multiply and dividing Duration by int or bigint
  • Remainder of Duration by Duration
  • Negation of a Duration
  • Difference between two points in time produces a Duration

Summary by CodeRabbit

  • New Features

    • Added arithmetic support for durations, including addition, subtraction, multiplication, division, remainder, and negation.
    • Added date and time arithmetic for instants, plain dates and times, and zoned date-times.
    • Plain times now wrap correctly across midnight when adding or subtracting durations.
    • Subtracting compatible date or time values now returns the elapsed duration.
    • Zoned date-time calculations preserve timezone information.
  • Bug Fixes

    • Improved generated client output by excluding interface-provided methods from class method collections.
  • Tests

    • Added comprehensive coverage for time arithmetic, wrapping, signed differences, timezone preservation, and integer operations.

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview Aug 12, 2026 7:27pm
promptfiddle2 Ready Ready Preview Aug 12, 2026 7:27pm

Request Review

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 August 11, 2026 23:30 Inactive
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds arithmetic operators for Duration, Instant, PlainDateTime, PlainTime, and ZonedDateTime. It adds time arithmetic tests and excludes interface implementation methods from generated class method collections.

Changes

Time arithmetic

Layer / File(s) Summary
Duration operators
baml_language/crates/baml_builtins2/baml_std/baml/ns_time/duration.baml
Duration supports addition, subtraction, multiplication, division, remainder, and negation using nanosecond values.
Temporal type operators
baml_language/crates/baml_builtins2/baml_std/baml/ns_time/instant.baml, baml_language/crates/baml_builtins2/baml_std/baml/ns_time/plaindatetime.baml, baml_language/crates/baml_builtins2/baml_std/baml/ns_time/plaintime.baml, baml_language/crates/baml_builtins2/baml_std/baml/ns_time/zoneddatetime.baml
Temporal types support duration addition and subtraction. Value subtraction returns signed Duration results. PlainTime wraps results within one day. ZonedDateTime preserves timezone metadata.
Arithmetic validation
baml_language/crates/baml_tests/baml_src/ns_time/time.baml
Tests cover operator results, integer and bigint operands, truncating division, midnight wrapping, date crossing, signed differences, and timezone behavior.

Interface method code generation

Layer / File(s) Summary
Interface method filtering
baml_language/crates/baml_project/src/client_codegen.rs, baml_language/sdk_tests/harness_setup/src/csharp.rs
Class generation skips methods linked to interface implementations. C# surface expectations retain only generated class members, including the Reader property for CsvRows.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Possibly related PRs

Suggested reviewers: sxlijin

Poem

A rabbit counts nanoseconds in flight,
Duration turns left, then turns right.
Clocks cross midnight and zones remain true,
Interface methods stay out of view.
Tests check each boundary in sight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding arithmetic operations for the baml.time types.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kai/stdlib

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
baml_language/crates/baml_tests/baml_src/ns_time/time.baml (1)

323-329: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a timezone-offset transition case.

The case at Line 325 starts after the local offset transition. later.timezone() and (later - base) can pass if arithmetic retains the timezone identifier but does not resolve the new local offset.

Add a case that adds one hour to 2024-03-10T01:00 in America/New_York. Assert that later.hour() is 3.

Proposed test
+test "zoned_arithmetic_applies_timezone_offset_transition" {
+    let base = baml.time.ZonedDateTime.from_components(
+        "America/New_York", 2024, 3, 10, hour = 1
+    );
+    let later = base + baml.time.Duration.from_hours(1n);
+    assert.equal(later.timezone(), "America/New_York");
+    assert.equal(later.hour(), 3);
+    assert.equal((later - base).to_hours(), 1n)
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_tests/baml_src/ns_time/time.baml` around lines 323
- 329, Extend the zoned arithmetic coverage in test
"zoned_arithmetic_preserves_the_timezone" with a base at 2024-03-10 01:00 in
America/New_York, add one hour using baml.time.Duration.from_hours, and assert
later.hour() equals 3 to verify the DST offset transition is resolved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@baml_language/crates/baml_tests/baml_src/ns_time/time.baml`:
- Around line 323-329: Extend the zoned arithmetic coverage in test
"zoned_arithmetic_preserves_the_timezone" with a base at 2024-03-10 01:00 in
America/New_York, add one hour using baml.time.Duration.from_hours, and assert
later.hour() equals 3 to verify the DST offset transition is resolved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4eb7252b-bbea-40fb-815d-c43bad45363d

📥 Commits

Reviewing files that changed from the base of the PR and between 5e6edc8 and 97f9758.

⛔ Files ignored due to path filters (10)
  • baml_language/crates/baml_cli/src/snapshots/baml_cli__describe_command_tests__render_builtin_package_listing.snap is excluded by !**/*.snap
  • baml_language/crates/baml_cli/src/snapshots/baml_cli__describe_render__tests__renders_builtin_class_with_impls.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/time.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_ppir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_tir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/src/compiler2_tir/snapshots/baml_tests__compiler2_tir__phase5__snapshot_baml_package_items.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • baml_language/crates/baml_builtins2/baml_std/baml/ns_time/duration.baml
  • baml_language/crates/baml_builtins2/baml_std/baml/ns_time/instant.baml
  • baml_language/crates/baml_builtins2/baml_std/baml/ns_time/plaindatetime.baml
  • baml_language/crates/baml_builtins2/baml_std/baml/ns_time/plaintime.baml
  • baml_language/crates/baml_builtins2/baml_std/baml/ns_time/zoneddatetime.baml
  • baml_language/crates/baml_tests/baml_src/ns_time/time.baml

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 26.2 MB 11.1 MB file 27.4 MB -1.2 MB (-4.4%) OK
packed-program Linux 🔒 16.9 MB 6.8 MB file 18.6 MB -1.7 MB (-8.9%) OK
baml-cli macOS 🔒 20.4 MB 9.7 MB file 21.3 MB -913.9 KB (-4.3%) OK
packed-program macOS 🔒 13.3 MB 6.0 MB file 14.5 MB -1.2 MB (-8.1%) OK
baml-cli Windows 🔒 21.9 MB 9.9 MB file 23.0 MB -1.1 MB (-4.7%) OK
packed-program Windows 🔒 14.1 MB 6.1 MB file 15.5 MB -1.4 MB (-9.1%) OK
bridge_wasm WASM 15.5 MB 🔒 4.2 MB gzip 4.6 MB -438.7 KB (-9.5%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

We don't generate interfaces and they can result in name conflicts
@vercel
vercel Bot temporarily deployed to Preview – beps August 12, 2026 19:18 Inactive
@2kai2kai2
2kai2kai2 enabled auto-merge August 12, 2026 19:24
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 August 12, 2026 19:27 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
baml_language/crates/baml_project/src/client_codegen.rs (1)

206-228: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the owning-class filtering path with a Rust unit test.

The new branch removes methods before they enter pending_methods. test_interface_and_implements_methods_do_not_reach_free_function_pool checks only the free-function filter, so it would still pass if this branch were removed. Add a test in the existing mod tests that asserts interface implementation methods are absent from the owning class’s static_methods and instance_methods.

As per coding guidelines: “**/*.rs: Prefer writing Rust unit tests over integration tests where possible” and “Always run cargo test --lib if you changed any Rust code.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_project/src/client_codegen.rs` around lines 206 -
228, Add a Rust unit test in the existing tests module covering the owning-class
filtering branch before methods enter pending_methods. Assert that interface
implementation methods are absent from the owning class’s static_methods and
instance_methods, while preserving the existing free-function test and behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/sdk_tests/harness_setup/src/csharp.rs`:
- Around line 466-470: Update the C# generation expectation for Csv/CsvRows.g.cs
in the surrounding test setup to assert that the removed Iter, IterAsync, Next,
and NextAsync members are absent, while retaining the existing Reader presence
assertion. Apply the same negative checks to each affected generated C# surface
represented by this test.

---

Nitpick comments:
In `@baml_language/crates/baml_project/src/client_codegen.rs`:
- Around line 206-228: Add a Rust unit test in the existing tests module
covering the owning-class filtering branch before methods enter pending_methods.
Assert that interface implementation methods are absent from the owning class’s
static_methods and instance_methods, while preserving the existing free-function
test and behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4de7e3ca-e37f-43a4-bd6c-0b22625154c5

📥 Commits

Reviewing files that changed from the base of the PR and between 97f9758 and c65bb41.

⛔ Files ignored due to path filters (2)
  • baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • baml_language/crates/baml_project/src/client_codegen.rs
  • baml_language/sdk_tests/harness_setup/src/csharp.rs

Comment thread baml_language/sdk_tests/harness_setup/src/csharp.rs
@2kai2kai2
2kai2kai2 added this pull request to the merge queue Aug 12, 2026
Merged via the queue into canary with commit 9ab3838 Aug 12, 2026
212 of 217 checks passed
@2kai2kai2
2kai2kai2 deleted the kai/stdlib branch August 12, 2026 20:34
meefs pushed a commit to meefs/baml that referenced this pull request Aug 15, 2026
…L#4446)

## Summary

- Fixes the deterministic C# verification failure in the baml_language
0.17.0 production release run:
https://github.com/BoundaryML/baml/actions/runs/31857280879
- Aligns the phase-12 package consumer with the generated C# surface
established by BoundaryML#4366, which intentionally omits methods inherited
through BAML interface implementations.
- Keeps runtime coverage for the C# CSV methods and resource fields that
are generated.

## Root cause

The phase-12 fixture is normally ignored because of B-1059, but the
production full-surface package verifier compiles and runs it. Its stale
calls to CsvReader.Iter/Next and CsvRows.Iter/Next no longer compile
after BoundaryML#4366 removed interface-implementation methods from generated
class method collections.

## Validation

- cargo nextest run -p sdk_test_csharp --all-features --run-ignored only
-E
test(test_phase12_executes_native_typed_resource_apis_lifetimes_and_state)
- dotnet build
sdk_tests/crates/csharp/phase12_resources/Phase12Resources.csproj
--configuration Release --no-restore
- git diff --check

## Release follow-up

After this merges and post-merge canary CI succeeds, 0.17.0 must be
dispatched from the new immutable baml-language source tag. This PR does
not publish or dispatch the release.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Updated C# CSV resource validation to verify headers, reader
availability, and the initial reading position.
* Simplified resource cleanup validation to ensure the active CSV reader
is properly closed.
* Removed checks for iterator identity, typed row decoding, and raw
record access.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

1 participant