Skip to content

Commit

Permalink
types: fix StrToDate handling of %h and %p (#17395) (#17498)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Jun 2, 2020
1 parent dd83050 commit 9ea0deb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
5 changes: 5 additions & 0 deletions types/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func (s *testTimeSuite) TestStrToDate(c *C) {
{`10:13 PM`, `%l:%i %p`, types.FromDate(0, 0, 0, 22, 13, 0, 0)},
{`12:00:00 AM`, `%h:%i:%s %p`, types.FromDate(0, 0, 0, 0, 0, 0, 0)},
{`12:00:00 PM`, `%h:%i:%s %p`, types.FromDate(0, 0, 0, 12, 0, 0, 0)},
{`12:00:00 PM`, `%I:%i:%s %p`, types.FromDate(0, 0, 0, 12, 0, 0, 0)},
{`1:00:00 PM`, `%h:%i:%s %p`, types.FromDate(0, 0, 0, 13, 0, 0, 0)},
{`18/10/22`, `%y/%m/%d`, types.FromDate(2018, 10, 22, 0, 0, 0, 0)},
{`8/10/22`, `%y/%m/%d`, types.FromDate(2008, 10, 22, 0, 0, 0, 0)},
{`69/10/22`, `%y/%m/%d`, types.FromDate(2069, 10, 22, 0, 0, 0, 0)},
Expand Down Expand Up @@ -133,6 +135,9 @@ func (s *testTimeSuite) TestStrToDate(c *C) {
{`18`, `%l`},
{`00:21:22 AM`, `%h:%i:%s %p`},
{`100/10/22`, `%y/%m/%d`},
{"2010-11-12 11 am", `%Y-%m-%d %H %p`},
{"2010-11-12 13 am", `%Y-%m-%d %h %p`},
{"2010-11-12 0 am", `%Y-%m-%d %h %p`},
}
for _, tt := range errTests {
var t types.Time
Expand Down
11 changes: 1 addition & 10 deletions types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ var dateFormatParserTable = map[string]dateFormatParser{
"%d": dayOfMonthNumeric, // Day of the month, numeric (0..31)
"%e": dayOfMonthNumeric, // Day of the month, numeric (0..31)
"%f": microSeconds, // Microseconds (000000..999999)
"%h": hour24TwoDigits, // Hour (01..12)
"%h": hour12Numeric, // Hour (01..12)
"%H": hour24Numeric, // Hour (00..23)
"%I": hour12Numeric, // Hour (01..12)
"%i": minutesNumeric, // Minutes, numeric (00..59)
Expand Down Expand Up @@ -2649,15 +2649,6 @@ func parseDigits(input string, count int) (int, bool) {
return int(v), true
}

func hour24TwoDigits(t *CoreTime, input string, ctx map[string]int) (string, bool) {
v, succ := parseDigits(input, 2)
if !succ || v >= 24 {
return input, false
}
t.setHour(uint8(v))
return input[2:], true
}

func secondsNumeric(t *CoreTime, input string, ctx map[string]int) (string, bool) {
result := oneOrTwoDigitRegex.FindString(input)
length := len(result)
Expand Down

0 comments on commit 9ea0deb

Please sign in to comment.