Skip to content

Commit

Permalink
fix 12pm case
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaibbq committed Feb 21, 2024
1 parent c430396 commit 202599f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions internal/function_time_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,22 +873,22 @@ func largeAMPMParser(text []rune, t *time.Time) (int, error) {
if len(text) < 2 {
return progress, fmt.Errorf("cannot parse am/pm format: remaining text [%s]", string(text))
}
progress += 2
toParse := string(text[:progress])
toParse := string(text[:2])
timeOfDay := strings.ToLower(toParse)
if timeOfDay != "am" && timeOfDay != "pm" {
return 0, fmt.Errorf("cannot parse am/pm format: [%s] is not am/pm", string(text))
}
return progress, nil
progress += 2

Check failure on line 881 in internal/function_time_parser.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to progress (ineffassign)
return 2, nil
}

func ampmPostProcessor(text []rune, t *time.Time) {
morning := strings.ToLower(string(text)) == "am"
hour := t.Hour()
if hour == 12 && morning {
hour = 0
if morning {
hour = hour % 12
}
if !morning {
if !morning && hour < 12 {
hour += 12
}
*t = time.Date(
Expand Down
4 changes: 2 additions & 2 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4256,11 +4256,11 @@ SELECT date, EXTRACT(ISOYEAR FROM date), EXTRACT(YEAR FROM date), EXTRACT(MONTH
},
{
name: "parse timestamp with %p",
query: `SELECT PARSE_TIMESTAMP("%I%p", "9am"), PARSE_TIMESTAMP("%I%p", "12am"), PARSE_TIMESTAMP("%l%p", " 2am"), PARSE_TIMESTAMP("%I%p", "10PM");`,
query: `SELECT PARSE_TIMESTAMP("%I%p", "9am"), PARSE_TIMESTAMP("%I%p", "12am"), PARSE_TIMESTAMP("%l%p", " 12pm"), PARSE_TIMESTAMP("%I%p", "10PM");`,
expectedRows: [][]interface{}{{
createTimestampFormatFromString("1970-01-01 09:00:00+00"),
createTimestampFormatFromString("1970-01-01 00:00:00+00"),
createTimestampFormatFromString("1970-01-01 02:00:00+00"),
createTimestampFormatFromString("1970-01-01 12:00:00+00"),
createTimestampFormatFromString("1970-01-01 22:00:00+00"),
}},
},
Expand Down

0 comments on commit 202599f

Please sign in to comment.