Repository navigation
Time: MRI 4.0 constructor argument forms (String/zone-object/coercion) - #517
Merged
Merged
Conversation
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>
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 MRI-Ruby-4.0.6 conformance of the
Timeconstructor family(
Time.new/Time.utc/Time.gm/Time.local/Time.mktime/Time.at/Time.now), all ininternal/vm/time.go.What was added
Time.utc("2000", "dec", "15", ...):three-letter month names, base-10 numeral parsing, and the
#to_str/#to_intprotocols (obj2int / month_arg semantics); nil fields fall backto their defaults.
argument for utc/local, including the C-style 10-argument gmtime
form (
sec, min, hour, mday, mon, year, …).+HH[:MM[:SS]]/+HHMM/UTC/ military-letter String forms; and#to_str/#to_int/#to_rcoercion. An hour field>= 24is now anout-of-range offset, not a format error.
Time.new(String)instant form with theprecision:keyword (ISO-8601-like parsing, sub-second truncation, bare-year form,
ASCII-compatibility check).
#local_to_utc(Time.new) and#utc_to_local(Time.now / Time.at);
#abbrfeeds%Z,#zonereturns the object.gmis now thesame Method object as
utc;getgmaliasesgetutc.ruby/spec deltas (core/time)
+102passing examples; errors118 -> 30; no per-spec regressions(verified against
origin/main). Remaining core/time failures areout of scope here: runtime
$TZ-dependent local-zone tests (rbgo'sTime.nowis UTC),Marshalhooks that live inmarshal_codec.go,Timesubclass instances, and sub-nanosecondprecision: nil(thestdlib-backed instant caps at 9 fractional digits).
Verification
go test ./...green;GOOS=wasip1 GOARCH=wasm go build ./...OK.gofmt -lclean on changed files.-coverpkgacross./internal/..., run over./...)reads 100.0%; every function changed in
time.gois at 100%.internal/vm/time_new_conformance_test.go(package
vm_test), asserted byte-for-byte against MRI 4.0.6.🤖 Generated with Claude Code