Skip to content

Commit

Permalink
util/types: fix parsing datatime 00-00-00 (#3536)
Browse files Browse the repository at this point in the history
00-00-00 should not be adjust year to 2000-00-00
  • Loading branch information
tiancaiamao authored Jun 23, 2017
1 parent 4db09e0 commit dcf0da9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion util/types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,11 @@ func parseDatetime(str string, fsp int) (Time, error) {
// we should adjust it.
// TODO: adjust year is very complex, now we only consider the simplest way.
if len(seps[0]) == 2 {
year = adjustYear(year)
if year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0 && fracStr == "" {
// Skip a special case "00-00-00".
} else {
year = adjustYear(year)
}
}

microsecond, overflow, err := parseFrac(fracStr, fsp)
Expand Down
2 changes: 2 additions & 0 deletions util/types/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func (s *testTimeSuite) TestDateTime(c *C) {
{"20121231113045", "2012-12-31 11:30:45"},
{"121231113045", "2012-12-31 11:30:45"},
{"2012-02-29", "2012-02-29 00:00:00"},
{"00-00-00", "0000-00-00 00:00:00"},
{"00-00-00 00:00:00.123", "2000-00-00 00:00:00"},
}

for _, test := range table {
Expand Down

0 comments on commit dcf0da9

Please sign in to comment.