Repository navigation
Time: advance MRI 4.0.6 conformance (aliases, zone preservation, strftime %g/%v/flags, UTC label, #<=>, #deconstruct_keys) - #541
Merged
Conversation
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Advances
core/timeMRI 4.0.6 conformance ininternal/vm/time.go(with matching unit tests). rubyspeccore/timerose from ~470 to 510 passing examples (about +40), with no regressions elsewhere in the suite.Fixes
#mon,#mday,#tv_sec,#tv_usec,#tv_nsec,#gmt_offset,#gmtoff,#gmt?,#isdst,#gmtime,#getgm,#ctime,#xmlschemanow share oneMethodrecord with their canonical name, soTime.instance_method(:alias) == Time.instance_method(:canonical)(the patterncomplex.goalready uses).#+/#-preserve the timezone object (plus/minus +1 each).timeShiftcarried the location but dropped the RubyzoneObj, so(t + n).zonelost aTime.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→FEBand%10hpads.#to_s/#inspectlabel a UTC instant "UTC" (inspect +4, to_s +1,_load+2). rbgo's UTC-location Times already answerutc?true and#zone"UTC"; repr now matches. Existing unit tests that pinned the old+0000forTime.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)
with_timezone, EST/PST/CET offsets, DST transitions): needs a zone DB beyond Go'stime.#round/#ceil/#floorexplicit-digit cases,%12Npicoseconds,Time.at+Rational subsec, some#+/#-float cases): Go'stime.Timeis nanosecond-resolution.Time.atreturning a non-UTC time / GMT-flag on dup/marshal: rbgo deliberately makesTime.at(numeric)a deterministic UTC instant.Time + Rationalvia the operator:binary()inarith.go(off-limits) intercepts a*Rationalright operand before the Time branch; the method path (t.+(r)) is already correct.#to_r-coercion mock cases andTimeincludingComparable: require touching VM-less coercion helpers / a post-prelude hook invm.go, outsidetime.go.Verification
go test ./internal/vm/green;GOOS=wasip1 GOARCH=wasm go build ./...OK;gofmt -lclean on changed files.time.go(registerTime,timeShift,repr,subsecValue,zoneValue,fieldValue,strftime,strftimeField) at 100.0% coverage.🤖 Generated with Claude Code