-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
util/types: re-implement check time related #2233
Merged
Merged
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
47ebaab
*: types.TimeInternal GoTime method would return error
tiancaiamao 9c03502
recover checkTime
tiancaiamao d1e394c
address comment
tiancaiamao 3c103db
util/time: ToPackedUint would return error for invalid timestamp
tiancaiamao 6c964c9
util/types: fix bug parseFrac overflow ignored during time Parse
tiancaiamao 0fa8e1a
fix and add more test
tiancaiamao 06331ee
make golint happy
tiancaiamao 3031d2f
util/types: provide time Format method
tiancaiamao b9b54c9
Merge branch 'master' into time
tiancaiamao 57d3cbf
Merge branch 'tiancaiamao/overflow' into time
tiancaiamao 6f79941
refact check method for Time
tiancaiamao 0dfb6a1
Merge branch 'master' into time
tiancaiamao a23fb69
address comment
tiancaiamao 09b521f
address comment
tiancaiamao b002458
address comment
tiancaiamao 52e67b5
address comment
tiancaiamao c36a514
remove unused checkTimeType
tiancaiamao 31dce0b
address comment
tiancaiamao f0b208f
address comment
tiancaiamao 530195b
Merge branch 'master' into tiancaiamao/check-time
tiancaiamao 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
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 |
---|---|---|
|
@@ -15,8 +15,6 @@ package types | |
|
||
import ( | ||
gotime "time" | ||
|
||
"github.com/juju/errors" | ||
) | ||
|
||
type mysqlTime struct { | ||
|
@@ -85,9 +83,17 @@ func (t mysqlTime) ISOWeek() (int, int) { | |
} | ||
|
||
func (t mysqlTime) GoTime() (gotime.Time, error) { | ||
err := checkTime(int(t.year), int(t.month), int(t.day), int(t.hour), int(t.minute), int(t.second), int(t.microsecond)) | ||
tm := gotime.Date(t.Year(), gotime.Month(t.Month()), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Microsecond()*1000, gotime.Local) | ||
return tm, errors.Trace(err) | ||
year, month, day := tm.Date() | ||
hour, minute, second := tm.Clock() | ||
microsec := tm.Nanosecond() / 1000 | ||
var err error | ||
if year != t.Year() || int(month) != t.Month() || day != t.Day() || | ||
hour != t.Hour() || minute != t.Minute() || second != t.Second() || | ||
microsec != t.Microsecond() { | ||
err = ErrInvalidTimeFormat | ||
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. return tm, err directly ? and we needn't init var at line 94 |
||
} | ||
return tm, err | ||
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. Add |
||
} | ||
|
||
func newMysqlTime(year, month, day, hour, minute, second, microsecond int) mysqlTime { | ||
|
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.
Please add comment for the following logic.