Repository navigation
fix(proto): handle the sign of negative Time and Time64 values - #1252
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
AmanBoronbaev
left a comment
There was a problem hiding this comment.
I checked the negative-duration change at 41b6f21 against ClickHouse 26.10.13.11. Parse followed by String matched the server for both Time and Time64(9) on five inputs: the negative and positive 999-hour endpoints, -01:02:03.456, and one nanosecond on either side of zero. For the subsecond cases I supplied only the integral part to Time. In particular, the server and the client both rendered -1 ns as -00:00:00.000000001, while the seconds-only value rendered as 00:00:00.
The new TestTime_Negative also passed locally.
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.
Fixes #1249
Summary
ParseTime32andParseTime64return a wrong value for a negativeTimetext, andString()prints a minus sign on each part.Cause:
-00hours,strconv.Atoireturns 0 and the sign is lost.String()formats each part of a negative value with its own sign.Fix:
-as the sign of the whole value.String()prints the sign one time, before the hours.ParseTime32still reads the old-1:-2:-3form.Tests:
TestTime_Negativeinproto/time_test.gofails onmainand passes with this change.go test ./proto/andgolangci-lint run ./proto/...pass. No test against a ClickHouse server was run.Checklist
TimeandTime64values inParseTime32,ParseTime64andString().This change was prepared with the help of an AI assistant.
Note
Low Risk
Localized proto time parsing/formatting fix with positive paths unchanged; only negative sign semantics change, which corrects a bug rather than altering production-critical paths.
Overview
Fixes incorrect handling of negative
Time32/Time64values inParseTime32,ParseTime64, andString().String: Negative durations now emit a single leading
-(e.g.-01:02:03) instead of a minus on each field.Parse: A leading
-on the hour field applies to the entire duration (including-00:00:01), with components taken in absolute value before negating the total;Time64applies the same rule to fractional nanoseconds.Compat: Positive formatting/parsing is unchanged; the legacy
-1:-2:-3form still parses to the same negative value.Adds
TestTime_Negativeround-trip coverage for parse/String()on both types.Reviewed by Cursor Bugbot for commit 41b6f21. Bugbot is set up for automated code reviews on this repo. Configure here.