Skip to content

Time: advance MRI 4.0.6 conformance (aliases, zone preservation, strftime %g/%v/flags, UTC label, #<=>, #deconstruct_keys) - #541

Merged
tannevaled merged 6 commits into
mainfrom
feat/agent-time
Aug 31, 2026
Merged

tannevaled merged 6 commits into
mainfrom
feat/agent-time

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Advances core/time MRI 4.0.6 conformance in internal/vm/time.go (with matching unit tests). rubyspec core/time rose from ~470 to 510 passing examples (about +40), with no regressions elsewhere in the suite.

Fixes

  • Alias identity (13 specs). #mon, #mday, #tv_sec, #tv_usec, #tv_nsec, #gmt_offset, #gmtoff, #gmt?, #isdst, #gmtime, #getgm, #ctime, #xmlschema now share one Method record with their canonical name, so Time.instance_method(:alias) == Time.instance_method(:canonical) (the pattern complex.go already uses).
  • #+ / #- preserve the timezone object (plus/minus +1 each). timeShift carried the location but dropped the Ruby zoneObj, so (t + n).zone lost a Time.new(..., tz)'s zone.
  • #strftime (+3). Added %g (two-digit commercial year) and %v (" 3-FEB-2001", alias of %e-%^b-%Y), and made flags/width apply through alias/composite directives so %^h → FEB and %10h pads.
  • #to_s / #inspect label a UTC instant "UTC" (inspect +4, to_s +1, _load +2). rbgo's UTC-location Times already answer utc? true and #zone "UTC"; repr now matches. Existing unit tests that pinned the old +0000 for Time.utc/Time.at/dry-types/MySQL output are updated.
  • #<=> with a non-Time argument (5). Reverses the comparison (other <=> self) and inverts the sign, returning nil when that is nil.
  • #deconstruct_keys (7). Added for pattern matching: nil returns the whole field hash, an Array returns the requested Symbol fields (ignoring non-Symbol / unknown keys), and any other argument raises TypeError.

Out of scope (reported, not fixed)

  • Timezone-database behavior (with_timezone, EST/PST/CET offsets, DST transitions): needs a zone DB beyond Go's time.
  • Sub-nanosecond precision (#round/#ceil/#floor explicit-digit cases, %12N picoseconds, Time.at+Rational subsec, some #+/#- float cases): Go's time.Time is nanosecond-resolution.
  • Time.at returning a non-UTC time / GMT-flag on dup/marshal: rbgo deliberately makes Time.at(numeric) a deterministic UTC instant.
  • Time + Rational via the operator: binary() in arith.go (off-limits) intercepts a *Rational right operand before the Time branch; the method path (t.+(r)) is already correct.
  • #to_r-coercion mock cases and Time including Comparable: require touching VM-less coercion helpers / a post-prelude hook in vm.go, outside time.go.

Verification

  • go test ./internal/vm/ green; GOOS=wasip1 GOARCH=wasm go build ./... OK; gofmt -l clean on changed files.
  • Every changed function in time.go (registerTime, timeShift, repr, subsecValue, zoneValue, fieldValue, strftime, strftimeField) at 100.0% coverage.

🤖 Generated with Claude Code

tannevaled and others added 6 commits August 31, 2026 20:48
Time#mon, #mday, #tv_sec, #tv_usec, #tv_nsec, #gmt_offset, #gmtoff,
#gmt?, #isdst, #gmtime, #getgm, #ctime and #xmlschema are documented
aliases in MRI: Time.instance_method(:alias) equals
Time.instance_method(:canonical). Previously each was defined with its
own native body, so the reflected UnboundMethods compared unequal.
Assign the canonical Method record under the alias name (as complex.go
already does) so the entries are identity-equal, flipping 13 core/time
rubyspec files green with no behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
MRI keeps a Time's zone through arithmetic: (t + n).zone and (t - n).zone
report the zone t was built with. timeShift dropped the Ruby timezone
object (zoneObj) when it built the shifted Time, so a Time.new(..., tz)
lost its zone on the first +/-. Carry zoneObj onto the result, flipping
the "preserves time zone" example in both core/time/plus_spec and
core/time/minus_spec green (the Go location was already preserved by
time.Time.Add).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Three MRI 4.0.6 strftime gaps in core/time/strftime_spec:
- %g (the commercial/ISO week year modulo 100) was unhandled and passed
  through verbatim; add it beside %G.
- %v (the VMS/Oracle date " 3-FEB-2001", an alias of %e-%^b-%Y) was
  missing; add it to the expansion table.
- An alias/composite directive discarded the parsed flags and width, so
  %^h rendered "Feb" not "FEB" and %10h did not pad. Route the expansion
  result through applyFlags so the GNU modifiers (^ upcase, _/0 pad, -
  no-pad, width) compose over %h and friends.

Flag-less expansions are unchanged (applyFlags is a no-op with no flags
and no width), so the existing %F/%T/%D/%R/%r/%X cases keep their output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Three MRI 4.0.6 conformance fixes in core/time:

- #to_s / #inspect label a UTC instant's zone "UTC" rather than the
  "+0000" offset (repr), since rbgo's UTC-location Times already answer
  utc? true and #zone "UTC". Fixes inspect_spec (4) and to_s_spec (1),
  and helped _load_spec (+2). Existing unit tests that pinned the old
  "+0000" for Time.utc/Time.at outputs are updated to "UTC".

- #<=> with a non-Time argument reverses the comparison (other <=> self)
  and inverts the sign, returning nil when that is nil, dispatching the
  sign test through the result's own #>/#< — fixes comparison_spec (5).

- #deconstruct_keys(keys) is added for pattern matching: nil returns the
  whole field hash (year..zone), an Array returns the requested Symbol
  fields (ignoring non-Symbol and unknown keys), and a non-Array/non-nil
  argument raises TypeError — fixes deconstruct_keys_spec (7). The subsec
  and zone readers are factored into shared helpers it reuses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Follow-up to the repr change: TestDryFromGo (dry-types Go time.Time
conversion) and TestMySQLValueTypes (MySQL DATETIME value) each render a
UTC-location Time, whose #to_s / #inspect now labels the zone "UTC"
rather than "+0000", matching MRI. These are the only two non-time_*
test files that print a UTC Time; the remaining "+0000" occurrences in
the suite are rfc2822/input strings and Date#rfc2822 output, unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit b0f604c into main Aug 31, 2026
12 of 13 checks passed
@tannevaled
tannevaled deleted the feat/agent-time branch August 31, 2026 23:06
tannevaled added a commit that referenced this pull request Sep 1, 2026
Locks in #535 (String methods: index/casecmp/chomp/gsub/scan/tr/... ~+110),
#536 (IO/StringIO reader+writer), #538 (Array#[]= auto-grow + mutators),
#539 (Range + Comparable), #540 (Struct + Data), #541 (Time). Measured
17983 passing on the pinned corpus, up from 17654.

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