Skip to content

Commit f086b3f

Browse files
author
James Cor
committed
fix more tests
1 parent 84b0609 commit f086b3f

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

sql/planbuilder/dateparse/date_test.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,48 @@ func TestParseDate(t *testing.T) {
1515
name string
1616
date string
1717
format string
18-
expected string
18+
expected interface{}
1919
}{
20-
{"simple", "Jan 3, 2000", "%b %e, %Y", "2000-01-03"},
21-
{"simple_with_spaces", "Nov 03 , 2000", "%b %e, %Y", "2000-11-03"},
22-
{"simple_with_spaces_2", "Dec 15 , 2000", "%b %e, %Y", "2000-12-15"},
23-
{"reverse", "2023/Feb/ 1", "%Y/%b/%e", "2023-02-01"},
24-
{"reverse_with_spaces", " 2023 /Apr/ 01 ", "%Y/%b/%e", "2023-04-01"},
25-
{"weekday", "Thu, Aug 5, 2021", "%a, %b %e, %Y", "2021-08-05"},
26-
{"weekday", "Fri, Aug 6, 2021", "%a, %b %e, %Y", "2021-08-06"},
27-
{"weekday", "Sat, Aug 7, 2021", "%a, %b %e, %Y", "2021-08-07"},
28-
{"weekday", "Sun, Aug 8, 2021", "%a, %b %e, %Y", "2021-08-08"},
29-
{"weekday", "Mon, Aug 9, 2021", "%a, %b %e, %Y", "2021-08-09"},
30-
{"weekday", "Tue, Aug 10, 2021", "%a, %b %e, %Y", "2021-08-10"},
31-
{"weekday", "Wed, Aug 11, 2021", "%a, %b %e, %Y", "2021-08-11"},
32-
33-
{"time_only", "22:23:00", "%H:%i:%s", "22:23:00"},
34-
{"with_time", "Sep 3, 22:23:00 2000", "%b %e, %H:%i:%s %Y", "2000-09-03 22:23:00"},
35-
{"with_pm", "May 3, 10:23:00 PM 2000", "%b %e, %h:%i:%s %p %Y", "2000-05-03 22:23:00"},
36-
{"lowercase_pm", "Jul 3, 10:23:00 pm 2000", "%b %e, %h:%i:%s %p %Y", "2000-07-03 22:23:00"},
37-
{"with_am", "Mar 3, 10:23:00 am 2000", "%b %e, %h:%i:%s %p %Y", "2000-03-03 10:23:00"},
38-
39-
{"month_number", "1 3, 10:23:00 pm 2000", "%c %e, %h:%i:%s %p %Y", "2000-01-03 22:23:00"},
40-
41-
{"day_with_suffix", "Jun 3rd, 10:23:00 pm 2000", "%b %D, %h:%i:%s %p %Y", "2000-06-03 22:23:00"},
42-
{"day_with_suffix_2", "Oct 21st, 10:23:00 pm 2000", "%b %D, %h:%i:%s %p %Y", "2000-10-21 22:23:00"},
43-
{"with_timestamp", "01/02/2003, 12:13:14", "%c/%d/%Y, %T", "2003-01-02 12:13:14"},
44-
45-
{"month_number", "03: 3, 20", "%m: %e, %y", "2020-03-03"},
46-
{"month_name", "march: 3, 20", "%M: %e, %y", "2020-03-03"},
47-
{"two_digit_date", "january: 3, 20", "%M: %e, %y", "2020-01-03"},
48-
{"two_digit_date_2000", "september: 3, 70", "%M: %e, %y", "1970-09-03"},
49-
{"two_digit_date_1900", "may: 3, 69", "%M: %e, %y", "2069-05-03"},
50-
51-
{"microseconds", "01/02/99 314", "%m/%e/%y %f", "1999-01-02 00:00:00.314000"},
52-
{"hour_number", "01/02/99 5:14", "%m/%e/%y %h:%i", "1999-01-02 05:14:00"},
53-
{"hour_number_2", "01/02/99 5:14", "%m/%e/%y %I:%i", "1999-01-02 05:14:00"},
54-
55-
{"timestamp", "01/02/99 05:14:12 PM", "%m/%e/%y %r", "1999-01-02 17:14:12"},
56-
{"date_with_seconds", "01/02/99 57", "%m/%e/%y %S", "1999-01-02 00:00:57"},
57-
58-
{"date_by_year_offset", "100 20", "%j %y", "2020-04-09"},
59-
{"date_by_year_offset_singledigit_year", "100 5", "%j %y", "2005-04-10"},
20+
{"simple", "Jan 3, 2000", "%b %e, %Y", time.Date(2000, time.January, 3, 0, 0, 0, 0, time.UTC)},
21+
{"simple_with_spaces", "Nov 03 , 2000", "%b %e, %Y", time.Date(2000, time.November, 3, 0, 0, 0, 0, time.UTC)},
22+
{"simple_with_spaces_2", "Dec 15 , 2000", "%b %e, %Y", time.Date(2000, time.December, 15, 0, 0, 0, 0, time.UTC)},
23+
{"reverse", "2023/Feb/ 1", "%Y/%b/%e", time.Date(2023, time.February, 1, 0, 0, 0, 0, time.UTC)},
24+
{"reverse_with_spaces", " 2023 /Apr/ 01 ", "%Y/%b/%e", time.Date(2023, time.April, 1, 0, 0, 0, 0, time.UTC)},
25+
{"weekday", "Thu, Aug 5, 2021", "%a, %b %e, %Y", time.Date(2021, time.August, 5, 0, 0, 0, 0, time.UTC)},
26+
{"weekday", "Fri, Aug 6, 2021", "%a, %b %e, %Y", time.Date(2021, time.August, 6, 0, 0, 0, 0, time.UTC)},
27+
{"weekday", "Sat, Aug 7, 2021", "%a, %b %e, %Y", time.Date(2021, time.August, 7, 0, 0, 0, 0, time.UTC)},
28+
{"weekday", "Sun, Aug 8, 2021", "%a, %b %e, %Y", time.Date(2021, time.August, 8, 0, 0, 0, 0, time.UTC)},
29+
{"weekday", "Mon, Aug 9, 2021", "%a, %b %e, %Y", time.Date(2021, time.August, 9, 0, 0, 0, 0, time.UTC)},
30+
{"weekday", "Tue, Aug 10, 2021", "%a, %b %e, %Y", time.Date(2021, time.August, 10, 0, 0, 0, 0, time.UTC)},
31+
{"weekday", "Wed, Aug 11, 2021", "%a, %b %e, %Y", time.Date(2021, time.August, 11, 0, 0, 0, 0, time.UTC)},
32+
33+
{"time_only", "22:23:00", "%H:%i:%s", time.Date(-1, time.November, 30, 22, 23, 0, 0, time.UTC)},
34+
{"with_time", "Sep 3, 22:23:00 2000", "%b %e, %H:%i:%s %Y", time.Date(2000, time.September, 3, 22, 23, 0, 0, time.UTC)},
35+
{"with_pm", "May 3, 10:23:00 PM 2000", "%b %e, %h:%i:%s %p %Y", time.Date(2000, time.May, 3, 10, 23, 0, 0, time.UTC)},
36+
{"lowercase_pm", "Jul 3, 10:23:00 pm 2000", "%b %e, %h:%i:%s %p %Y", time.Date(2000, time.July, 3, 10, 23, 0, 0, time.UTC)},
37+
{"with_am", "Mar 3, 10:23:00 am 2000", "%b %e, %h:%i:%s %p %Y", time.Date(2000, time.March, 3, 10, 23, 0, 0, time.UTC)},
38+
39+
{"month_number", "1 3, 10:23:00 pm 2000", "%c %e, %h:%i:%s %p %Y", time.Date(2000, time.January, 3, 10, 23, 0, 0, time.UTC)},
40+
41+
{"day_with_suffix", "Jun 3rd, 10:23:00 pm 2000", "%b %D, %h:%i:%s %p %Y", time.Date(2000, time.June, 3, 10, 23, 0, 0, time.UTC)},
42+
{"day_with_suffix_2", "Oct 21st, 10:23:00 pm 2000", "%b %D, %h:%i:%s %p %Y", time.Date(2000, time.October, 21, 10, 23, 0, 0, time.UTC)},
43+
{"with_timestamp", "01/02/2003, 12:13:14", "%c/%d/%Y, %T", time.Date(2003, time.January, 2, 12, 13, 14, 0, time.UTC)},
44+
45+
{"month_number", "03: 3, 20", "%m: %e, %y", time.Date(2020, time.March, 3, 0, 0, 0, 0, time.UTC)},
46+
{"month_name", "march: 3, 20", "%M: %e, %y", time.Date(2020, time.March, 3, 0, 0, 0, 0, time.UTC)},
47+
{"two_digit_date", "january: 3, 20", "%M: %e, %y", time.Date(2020, time.January, 3, 0, 0, 0, 0, time.UTC)},
48+
{"two_digit_date_2000", "september: 3, 70", "%M: %e, %y", time.Date(1970, time.September, 3, 0, 0, 0, 0, time.UTC)},
49+
{"two_digit_date_1900", "may: 3, 69", "%M: %e, %y", time.Date(2069, time.May, 3, 0, 0, 0, 0, time.UTC)},
50+
51+
{"microseconds", "01/02/99 314", "%m/%e/%y %f", time.Date(1999, time.January, 2, 0, 0, 0, 314000, time.UTC)},
52+
{"hour_number", "01/02/99 5:14", "%m/%e/%y %h:%i", time.Date(1999, time.January, 2, 5, 14, 0, 0, time.UTC)},
53+
{"hour_number_2", "01/02/99 5:14", "%m/%e/%y %I:%i", time.Date(1999, time.January, 2, 5, 14, 0, 0, time.UTC)},
54+
55+
{"timestamp", "01/02/99 05:14:12 PM", "%m/%e/%y %r", time.Date(1999, time.January, 2, 5, 14, 12, 0, time.UTC)},
56+
{"date_with_seconds", "01/02/99 57", "%m/%e/%y %S", time.Date(1999, time.January, 2, 0, 0, 57, 0, time.UTC)},
57+
58+
{"date_by_year_offset", "100 20", "%j %y", time.Date(2020, time.April, 9, 0, 0, 0, 0, time.UTC)},
59+
{"date_by_year_offset_singledigit_year", "100 5", "%j %y", time.Date(2005, time.April, 10, 0, 0, 0, 0, time.UTC)},
6060
}
6161

6262
for _, tt := range tests {
@@ -87,9 +87,9 @@ func TestConversionFailure(t *testing.T) {
8787
expectedError string
8888
}{
8989
// with strict mode with NO_ZERO_IN_DATE,NO_ZERO_DATE enabled, these tests result NULL
90-
{"no_year", "Jan 3", "%b %e", "0000-01-03", ""},
91-
{"no_day", "Jan 2000", "%b %y", "2020-01-00", ""},
92-
{"day_of_month_and_day_of_year", "Jan 3, 100 2000", "%b %e, %j %y", "2020-04-09", ""},
90+
{"no_year", "Jan 3", "%b %e", time.Date(0, time.January, 3, 0, 0, 0, 0, time.UTC), ""},
91+
{"no_day", "Jan 2000", "%b %y", time.Date(2019, time.December, 31, 0, 0, 0, 0, time.UTC), ""},
92+
{"day_of_month_and_day_of_year", "Jan 3, 100 2000", "%b %e, %j %y", time.Date(2020, time.April, 9, 0, 0, 0, 0, time.UTC), ""},
9393

9494
{"24hour_time_with_pm", "May 3, 10:23:00 PM 2000", "%b %e, %H:%i:%s %p %Y", nil, "cannot use 24 hour time (H) with AM/PM (p)"},
9595
{"specifier_end_of_line", "Jan 3", "%b %e %", nil, `"%" found at end of format string`},

0 commit comments

Comments
 (0)