Skip to content

Time: advance MRI 4.0.6 conformance (arithmetic, sub-nanosecond precision, timezones) - #563

Merged
tannevaled merged 8 commits into
mainfrom
feat/agent-time2
Sep 4, 2026
Merged

tannevaled merged 8 commits into
mainfrom
feat/agent-time2

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Advances MRI 4.0.6 conformance of core/time from ~509 to 543 passing
(rubyspec corpus), with no regressions. Every function changed keeps 100% merged
coverage; suite, wasip1 wasm build, and gofmt all green.

Changes (internal/vm/time.go, arith.go, vm.go)

  • Exact Time#+ / Time#-: routed through a VM-aware path so a Rational/Float
    shift is coerced with MRI's num_exact (Integer/Rational exact, Float via its
    exact #to_r, other objects via #to_r+#to_int, String/nil rejected) and
    applied to the nanosecond; Time + Time raises. Fixes coercion TypeErrors and
    negative-Float truncation. (plus 12→20, minus 13→19)
  • Sub-nanosecond precision (frac): a big.Rat field holds the sub-second
    part below one nanosecond, so #subsec/#to_r keep MRI's exact value through
    Time.at(Float/Rational), +/-, and Time.new(String, precision:) (which now
    keeps all digits for precision: nil/negative). Whole-nanosecond fields
    unchanged.
  • Runtime timezone: the local zone is resolved from ENV['TZ'] (Go tzdata), so
    with_timezone blocks get DST-aware IANA zones (EST/EDT…); an unloadable name
    defaults to UTC. (zone 4→6, utc_offset 3→6)
  • getlocal/localtime with a timezone object (#utc_to_local). (getlocal
    16→19, localtime 19→20)
  • Exact Rational seconds for Time.utc/local, so a value like "25.02" is
    20_000_000 ns not 19_999_999. (ceil/floor/round all green)
  • strftime %Z emits nothing for an offset-only zone; "-00:00" is RFC 3339
    unknown-offset UTC (#zone → "UTC"). Time.at(Float::INFINITY) raises
    FloatDomainError.
  • Time includes Comparable (#between?/#clamp).

Tested in internal/vm/time_residuals_wave11_test.go (fixed instants only) plus
extended conformance/file-ops tests. Out of scope: utc_spec (63 examples gated
by a parser gap — guard -> {} do…end), fractional UTC offsets, find_timezone,
and Marshal-based timezone tests.

🤖 Generated with Claude Code

tannevaled and others added 8 commits September 4, 2026 23:03
Committed to protect against scratchpad purge; to be finished, verified and
squashed before the PR is opened.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… Rational seconds

Route Time#+/#- through a VM-aware path so a Rational/Float shift is coerced
with MRI num_exact and applied to the nanosecond (fixing coercion errors and
negative-Float truncation); reject Time+Time. Handle a timezone object in
Time#getlocal/#localtime via #utc_to_local. Parse a Rational seconds field for
Time.utc/local exactly instead of through a lossy Float64.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Resolve the local timezone dynamically from ENV['TZ'] (Go tzdata), so a spec's
with_timezone block gets DST-aware IANA zones (EST/EDT etc.) and an unloadable
name defaults to UTC. strftime %Z now emits nothing for an offset-only zone
(matching MRI, not the numeric offset). A '-00:00' offset string is RFC 3339
unknown-offset UTC, so #zone reports 'UTC'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Carry a big.Rat 'frac' for the sub-second part below one nanosecond that Go's
instant cannot hold, so Time#+/#- and Time.at(Float/Rational) keep MRI's exact
sub-second in #subsec and #to_r (whole-nanosecond fields unchanged). A
non-finite Time.at Float now raises FloatDomainError.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
precision: nil or a negative count now keeps every sub-second digit (past the
ninth into frac) instead of clamping to 9, matching MRI 4.0.6; the default still
keeps 9 and an explicit count truncates.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Time.include?(Comparable) is now true (MRI mixes it in); Time's own #<=> drives
Comparable's #between?/#clamp. Added in the post-prelude phase so the module
exists.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Removing timeOp orphaned numFloat's non-Integer branches; File.utime is its
remaining caller and legitimately accepts Float/Rational second counts and
rejects non-numerics, so exercise all branches there.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit fcbcfd8 into main Sep 4, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/agent-time2 branch September 4, 2026 22:40
tannevaled added a commit that referenced this pull request Sep 5, 2026
Locks in #561 (StringIO / buffer IO), #562 (String non-encoding methods) and
#563 (Time). Measured 18650 passing on the pinned corpus, up from 18582.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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