Skip to content

Time: MRI 4.0 constructor argument forms (String/zone-object/coercion) - #517

Merged
tannevaled merged 2 commits into
mainfrom
feat/agent-time
Aug 30, 2026
Merged

tannevaled merged 2 commits into
mainfrom
feat/agent-time

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Advances MRI-Ruby-4.0.6 conformance of the Time constructor family
(Time.new / Time.utc / Time.gm / Time.local / Time.mktime /
Time.at / Time.now), all in internal/vm/time.go.

What was added

  • String / coerced calendar fields — Time.utc("2000", "dec", "15", ...):
    three-letter month names, base-10 numeral parsing, and the #to_str /
    #to_int protocols (obj2int / month_arg semantics); nil fields fall back
    to their defaults.
  • Fractional seconds (Float/Rational) and the microseconds 7th
    argument
    for utc/local, including the C-style 10-argument gmtime
    form
    (sec, min, hour, mday, mon, year, …).
  • utc_offset resolution — Integer/Float/Rational seconds; the
    +HH[:MM[:SS]] / +HHMM / UTC / military-letter String forms; and
    #to_str / #to_int / #to_r coercion. An hour field >= 24 is now an
    out-of-range offset, not a format error.
  • The Ruby 3.2+ Time.new(String) instant form with the precision:
    keyword (ISO-8601-like parsing, sub-second truncation, bare-year form,
    ASCII-compatibility check).
  • Timezone objects via #local_to_utc (Time.new) and #utc_to_local
    (Time.now / Time.at); #abbr feeds %Z, #zone returns the object.
  • Two-tier range errors (argument vs field out of range); gm is now the
    same Method object as utc; getgm aliases getutc.

ruby/spec deltas (core/time)

spec before after
new_spec 58 113
local_spec 27 46
at_spec 27 37
now_spec 10 18
gm_spec 0 1
core/time total 371 473

+102 passing examples; errors 118 -> 30; no per-spec regressions
(verified against origin/main). Remaining core/time failures are
out of scope here: runtime $TZ-dependent local-zone tests (rbgo's
Time.now is UTC), Marshal hooks that live in marshal_codec.go,
Time subclass instances, and sub-nanosecond precision: nil (the
stdlib-backed instant caps at 9 fractional digits).

Verification

  • go test ./... green; GOOS=wasip1 GOARCH=wasm go build ./... OK.
  • gofmt -l clean on changed files.
  • Merged coverage (-coverpkg across ./internal/..., run over ./...)
    reads 100.0%; every function changed in time.go is at 100%.
  • New tests live in internal/vm/time_new_conformance_test.go
    (package vm_test), asserted byte-for-byte against MRI 4.0.6.

🤖 Generated with Claude Code

tannevaled and others added 2 commits August 30, 2026 23:29
Bring Time.new / Time.utc / Time.local / Time.at / Time.now up to MRI
4.0.6 conformance across their full argument surface:

- String and #to_str/#to_int calendar fields, short month names, and
  base-10 numeral parsing (obj2int / month_arg semantics); nil fields
  fall back to their defaults.
- Fractional seconds (Float/Rational) and the microseconds 7th argument
  for utc/local, including the C-style 10-argument gmtime form.
- utc_offset resolution: Integer/Float/Rational seconds, the +HH[:MM[:SS]]
  / UTC / military-letter String forms, and #to_str/#to_int/#to_r
  coercion; an hour field >= 24 is an out-of-range offset, not a format
  error.
- The Ruby 3.2+ Time.new(String) instant form with the precision: keyword.
- Timezone objects via #local_to_utc (Time.new) and #utc_to_local
  (Time.now / Time.at), with #abbr feeding %Z and #zone returning the
  object.
- Two-tier range errors (argument vs field out of range) and gm aliased
  to the same Method object as utc; getgm aliases getutc.

core/time ruby/spec: pass 371 -> 475 (new 58->113, local 27->46,
at 27->37, now 10->18, gm 0->1), no per-spec regressions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add targeted vm_test cases for every branch of the new Time constructor
code (Numeric #to_r coercion, signed String fields, timezone-object
result variants, Time#+ via send driving numFloat) and remove a
dead sub-nanosecond truncation now that precision is always clamped to
[0, 9], bringing the changed functions to full statement coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 0d3040c into main Aug 30, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/agent-time branch August 30, 2026 22:28
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