Repository navigation
Time: advance MRI 4.0.6 conformance (arithmetic, sub-nanosecond precision, timezones) - #563
Merged
Merged
Conversation
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>
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 4.0.6 conformance of
core/timefrom ~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)Time#+/Time#-: routed through a VM-aware path so a Rational/Floatshift is coerced with MRI's
num_exact(Integer/Rational exact, Float via itsexact
#to_r, other objects via#to_r+#to_int, String/nil rejected) andapplied to the nanosecond;
Time + Timeraises. Fixes coercionTypeErrors andnegative-Float truncation. (
plus12→20,minus13→19)frac): abig.Ratfield holds the sub-secondpart below one nanosecond, so
#subsec/#to_rkeep MRI's exact value throughTime.at(Float/Rational),+/-, andTime.new(String, precision:)(which nowkeeps all digits for
precision: nil/negative). Whole-nanosecond fieldsunchanged.
ENV['TZ'](Go tzdata), sowith_timezoneblocks get DST-aware IANA zones (EST/EDT…); an unloadable namedefaults to UTC. (
zone4→6,utc_offset3→6)getlocal/localtimewith a timezone object (#utc_to_local). (getlocal16→19,
localtime19→20)Time.utc/local, so a value like"25.02"is20_000_000ns not19_999_999. (ceil/floor/roundall green)%Zemits nothing for an offset-only zone;"-00:00"is RFC 3339unknown-offset UTC (
#zone→"UTC").Time.at(Float::INFINITY)raisesFloatDomainError.TimeincludesComparable(#between?/#clamp).Tested in
internal/vm/time_residuals_wave11_test.go(fixed instants only) plusextended conformance/file-ops tests. Out of scope:
utc_spec(63 examples gatedby a parser gap —
guard -> {} do…end), fractional UTC offsets,find_timezone,and Marshal-based timezone tests.
🤖 Generated with Claude Code