-
Notifications
You must be signed in to change notification settings - Fork 14.6k
MINOR: Fix an off-by-one issue in ValuesTest #20520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Alex <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Fixes an off-by-one error in the ValuesTest that occurred when local time falls on a different day than UTC time. The test was using LocalDate.ofEpochDay(days)
which could result in incorrect date conversion when timezone differences cause day boundaries to differ between local and UTC time.
- Replaces
LocalDate.ofEpochDay(days)
withlocalTime.format(DateTimeFormatter.ISO_LOCAL_DATE)
to ensure consistent local time handling - Removes unused
LocalDate
import
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@@ -903,7 +901,7 @@ public void shouldConvertDateValues() { | |||
|
|||
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd" | |||
LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS); | |||
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE)); | |||
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, localTime.format(DateTimeFormatter.ISO_LOCAL_DATE)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable days
is referenced in the original code but not visible in this diff. If days
was calculated from localTime
, this change may not fix the off-by-one issue as intended, since localTime.format(DateTimeFormatter.ISO_LOCAL_DATE)
will still use the same local date that could differ from UTC. Consider using a fixed date string or ensuring the test uses UTC time consistently.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change may not fix the off-by-one issue as intended, since localTime.format(DateTimeFormatter.ISO_LOCAL_DATE) will still use the same local date that could differ from UTC.
@WenHsuanYu What do you think for this comment?
Signed-off-by: Alex <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Testing in timezone one day ahead of UTC was successful.
This test case ensures that the parser can convert ISO8601 correctly.
However, when the local time falls on a different day than the UTC time,
there will be an off-by-one issue.
I changed the test to convert the local time and then compare it with
the expected local time. This should fix the off-by-one issue.
Reference
link
Reviewers: Andrew Schofield [email protected]