Repository navigation
Decode text timestamps with timezone offsets of a day or more (SET TIME ZONE 30 no longer raises) - #766
Open
czj wants to merge 2 commits into
Open
Decode text timestamps with timezone offsets of a day or more (SET TIME ZONE 30 no longer raises)#766czj wants to merge 2 commits into
czj wants to merge 2 commits into
Conversation
PostgreSQL accepts SET TIME ZONE offsets up to 167:59:59 and prints them
as is ("+30", "+100", "-24:00:01"). Ruby's Time can't carry an offset of
a day or more, so the decoder raised "utc_offset out of range", and
three digit hours fell back to a String.
Read the third hour digit, and keep the instant of values whose offset
doesn't fit, returned as UTC or local time per TIMESTAMP_APP_*.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TruffleRuby's Time raises ArgumentError on a utc_offset of 86399, which CRuby accepts. Co-Authored-By: Claude Opus 5.5 <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.
Another one from the #761 review. PostgreSQL accepts
SET TIME ZONEoffsets up to ±167:59:59 and prints them as is, so afterSET TIME ZONE 30,SELECT now()comes back as2024-01-02 18:00:00+30.PG::TextDecoder::TimestampraisesArgumentError: utc_offset out of rangeon that, because Ruby'sTimeonly takes offsets under a day, and the whole query fails. From 100 hours on, the offset has a third digit, which the parser doesn't expect, so the value comes back as aString.This reads the third digit, only when the first two aren't
00, since PostgreSQL prints hours with%02dand the existing spec rejects+000:25:21. When the offset can't go into aTime, the decoder keeps the instant and returns it in UTC, or in local time withTIMESTAMP_APP_LOCAL, the way it already does for values without an offset. That's the one trade-off: the original offset is lost, but I couldn't find aTimethat holds it. Offsets under a day go through the same code as before.To check it against the server, I decoded 5 timestamps from 1901 to 294276 under every quarter-hour offset from -167 to +167 hours, with
BasicTypeMapForResultson PostgreSQL 18.6 and Ruby 4.0.9 (arm64-darwin), and compared them withto_char(t AT TIME ZONE 'UTC', …). With this patch, all 6,685 values match, and so do 4,020 more from 4713 BC to 1883 compared withextract(epoch). On master, 608 offsets make the query raise, and 2,690 values are wrong. I also compiled it with the fast path disabled to exercise the 32-bittime_tpath, and the timestamp specs pass there too, in UTC and inEurope/Paris. The new spec fails on master.Is UTC the fallback you'd expect here, or would you rather raise a clearer error?
🤖 Generated with Claude Code, but prompted, read, and verified by @czj, a caring human :)