-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
evalengine: Internal cleanup and consistency fixes #14854
Merged
dbussink
merged 5 commits into
vitessio:main
from
planetscale:dbussink/evalengine-cleanup
Dec 27, 2023
+167
−89
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8a75ccb
evalengine: Internal cleanup and consistency fixes
dbussink 1b2ed6f
Use correct int value
dbussink bf08036
Handle time only values for rounding
dbussink bc268a7
Fix additional size typing
dbussink f908537
Merge branch 'main' into dbussink/evalengine-cleanup
dbussink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,12 +432,12 @@ func (t Time) AddInterval(itv *Interval, stradd bool) (Time, uint8, bool) { | |
return dt.Time, itv.precision(stradd), ok | ||
} | ||
|
||
func (t Time) toSeconds() int { | ||
tsecs := t.Hour()*secondsPerHour + t.Minute()*secondsPerMinute + t.Second() | ||
func (t Time) toDuration() time.Duration { | ||
dur := time.Duration(t.hour)*time.Hour + time.Duration(t.minute)*time.Minute + time.Duration(t.second)*time.Second + time.Duration(t.nanosecond)*time.Nanosecond | ||
if t.Neg() { | ||
return -tsecs | ||
return -dur | ||
} | ||
return tsecs | ||
return dur | ||
} | ||
|
||
func (d Date) ToStdTime(loc *time.Location) (out time.Time) { | ||
|
@@ -569,8 +569,12 @@ func (dt DateTime) Round(p int) (r DateTime) { | |
return r | ||
} | ||
|
||
func (dt DateTime) toSeconds() int { | ||
return (dt.Date.Day()-1)*secondsPerDay + dt.Time.toSeconds() | ||
func (dt DateTime) toDuration() time.Duration { | ||
dur := dt.Time.toDuration() | ||
if !dt.Date.IsZero() { | ||
dur += time.Duration(dt.Date.Day()-1) * durationPerDay | ||
} | ||
return dur | ||
} | ||
|
||
func (dt *DateTime) addInterval(itv *Interval) bool { | ||
|
@@ -580,29 +584,25 @@ func (dt *DateTime) addInterval(itv *Interval) bool { | |
return false | ||
} | ||
|
||
nsec := dt.Time.Nanosecond() + itv.nsec | ||
sec := dt.toSeconds() + itv.toSeconds() + (nsec / int(time.Second)) | ||
nsec = nsec % int(time.Second) | ||
|
||
if nsec < 0 { | ||
nsec += int(time.Second) | ||
sec-- | ||
} | ||
dur := dt.toDuration() | ||
dur += itv.toDuration() | ||
days := time.Duration(0) | ||
if !dt.Date.IsZero() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rounding shouldn't move days if we're a Time instance. We then can have more than 24 hours. |
||
days = dur / durationPerDay | ||
dur -= days * durationPerDay | ||
|
||
days := sec / secondsPerDay | ||
sec -= days * secondsPerDay | ||
|
||
if sec < 0 { | ||
sec += secondsPerDay | ||
days-- | ||
if dur < 0 { | ||
dur += durationPerDay | ||
days-- | ||
} | ||
} | ||
|
||
dt.Time.nanosecond = uint32(nsec) | ||
dt.Time.second = uint8(sec % secondsPerMinute) | ||
dt.Time.minute = uint8((sec / secondsPerMinute) % secondsPerMinute) | ||
dt.Time.hour = uint16(sec / secondsPerHour) | ||
dt.Time.nanosecond = uint32((dur % time.Second) / time.Nanosecond) | ||
dt.Time.second = uint8((dur % time.Minute) / time.Second) | ||
dt.Time.minute = uint8((dur % time.Hour) / time.Minute) | ||
dt.Time.hour = uint16(dur / time.Hour) | ||
|
||
daynum := mysqlDayNumber(dt.Date.Year(), dt.Date.Month(), 1) + days | ||
daynum := mysqlDayNumber(dt.Date.Year(), dt.Date.Month(), 1) + int(days) | ||
if daynum < 0 || daynum > maxDay { | ||
return false | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
When we have a zero date (and thus we're a Time type), we don't include the day bit to have a correct duration.