Skip to content

Add realtime clock support - #157

Merged
lalinsky merged 1 commit into
zig-0.16from
realtime-clock
Dec 11, 2025
Merged

lalinsky merged 1 commit into
zig-0.16from
realtime-clock

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Summary

  • Add support for .real clock in nowImpl using aio.system.time.now(.realtime)
  • Simplify nowImpl to use aio.system.time.now for both monotonic and realtime clocks
  • Add test for realtime clock functionality

Test plan

  • Run ./check.sh - all 188 tests pass
  • New test verifies realtime clock returns reasonable timestamps and advances correctly

@coderabbitai

coderabbitai Bot commented Dec 11, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The nowImpl function in src/stdio.zig was refactored to replace Runtime-based clock handling with a unified aio.system.time.now approach. Clock mappings changed to route Awake/Boot to monotonic and Real to realtime clocks, with a test added validating realtime clock behavior.

Changes

Cohort / File(s) Summary
Clock mechanism refactor
src/stdio.zig
Replaced Runtime pointer-based clock switching with aio.system.time.now system call. Updated clock-to-time mapping: Awake/Boot → monotonic, Real → realtime. Nanoseconds conversion now derives from milliseconds with i96 casting. Added test validating realtime clock returns post-2020-01-01 timestamp and elapsed time tracking.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Clock mapping logic: Verify the new Awake/Boot→monotonic and Real→realtime routing is correct and doesn't introduce clock mismatch issues
  • Nanoseconds conversion: Check that milliseconds-to-nanoseconds conversion via i96 casting handles precision and overflow correctly
  • Test coverage: Confirm the realtime clock test adequately validates timestamp accuracy and elapsed time calculation
  • Integration: Ensure removal of Runtime dependency doesn't break other code paths relying on nowImpl

Poem

⏰ Time marches on in nanos bright,
From system calls in steady flight,
No Runtime ghosts, just clocks aligned,
Real and awake, their paths defined,
The moments tick—let tests ensure the light! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: adding realtime clock support to the codebase, which aligns with the core modification in nowImpl.
Description check ✅ Passed The description accurately covers the changeset: adding .real clock support via aio.system.time.now, simplifying nowImpl, and adding a test with verification that all 188 tests pass.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch realtime-clock

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8725899 and 09cdb18.

📒 Files selected for processing (1)
  • src/stdio.zig (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.zig

📄 CodeRabbit inference engine (CLAUDE.md)

Use zig env to get the path to the Zig standard library when needed

Files:

  • src/stdio.zig
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test (windows-latest)
🔇 Additional comments (2)
src/stdio.zig (2)

904-925: Good test coverage for the new realtime clock.

Validates two things: (1) the timestamp is a plausible wall-clock value, and (2) it advances correctly after sleeping. The epoch constant 1577836800 is 2020-01-01 UTC — might be worth a one-liner comment for the next reader, but not a blocker.


497-505: Implementation is correct—the conversion math is sound.

The variable naming (ms) and documented behavior in Runtime confirm that aio.system.time.now returns milliseconds. Multiplying by 1,000,000 correctly converts to nanoseconds (existing tests validate this against epoch timestamps). The i96 cast prevents overflow. No changes needed.


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 and usage tips.

@lalinsky

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 11, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lalinsky
lalinsky merged commit 7d5b525 into zig-0.16 Dec 11, 2025
@lalinsky
lalinsky deleted the realtime-clock branch December 11, 2025 13:46
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