Skip to content

Commit 23fc766

Browse files
committed
added expected time values
1 parent e9291ce commit 23fc766

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

enginetest/enginetests.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6148,6 +6148,9 @@ func TestSQLLogicTests(t *testing.T, harness Harness) {
61486148
}
61496149

61506150
func TestTimeQueryTests(t *testing.T, harness Harness) {
6151+
// "America/Phoenix" is a non-UTC time zone that does not observe daylight savings time
6152+
phoenixTimeZone, _ := time.LoadLocation("America/Phoenix")
6153+
mockNow := time.Date(2025, time.July, 23, 9, 43, 0, 0, phoenixTimeZone)
61516154
for _, script := range queries.TimeQueryTests {
61526155
if sh, ok := harness.(SkippingHarness); ok {
61536156
if sh.SkipQueryTest(script.Name) {
@@ -6157,7 +6160,10 @@ func TestTimeQueryTests(t *testing.T, harness Harness) {
61576160
continue
61586161
}
61596162
}
6160-
TestScript(t, harness, script)
6163+
sql.RunWithNowFunc(func() time.Time { return mockNow }, func() error {
6164+
TestScript(t, harness, script)
6165+
return nil
6166+
})
61616167
}
61626168
}
61636169

enginetest/queries/time_queries.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package queries
33
import (
44
"github.com/dolthub/go-mysql-server/sql"
55
"github.com/dolthub/go-mysql-server/sql/types"
6+
"time"
67
)
78

89
var TimeQueryTests = []ScriptTest{
@@ -18,24 +19,24 @@ var TimeQueryTests = []ScriptTest{
1819
},
1920
{
2021
Query: "select now()",
21-
Expected: []sql.Row{{""}}, // july 23, 2025 16:43
22+
Expected: []sql.Row{{time.Date(2025, time.July, 23, 16, 43, 0, 0, time.UTC)}},
2223
},
2324
{
2425
Query: "set time_zone='-5:00'",
2526
Expected: []sql.Row{{types.NewOkResult(0)}},
2627
},
2728
{
2829
Query: "select now()",
29-
Expected: []sql.Row{{""}}, // july 23, 2025 11:43
30+
Expected: []sql.Row{{time.Date(2025, time.July, 23, 11, 43, 0, 0, time.UTC)}},
3031
},
3132
{
32-
// doesn't observe daylight savings time so time zone does not change
33+
// doesn't observe daylight savings time
3334
Query: "set time_zone='Pacific/Honolulu'",
3435
Expected: []sql.Row{{types.NewOkResult(0)}},
3536
},
3637
{
3738
Query: "select now()",
38-
Expected: []sql.Row{{""}}, // july 23, 2025 6:43am
39+
Expected: []sql.Row{{time.Date(2025, time.July, 23, 6, 43, 0, 0, time.UTC)}},
3940
},
4041
{
4142
// https://github.com/dolthub/dolt/issues/9559

sql/time.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Package time contains low-level utility functions for working with time.Time values and timezones.
15+
// Contains low-level utility functions for working with time.Time values and timezones.
1616
package sql
1717

1818
import (
@@ -29,6 +29,8 @@ var offsetRegex = regexp.MustCompile(`(?m)^([+\-])(\d{1,2}):(\d{2})$`)
2929
// ConvertTimeZone converts |datetime| from one timezone to another. |fromLocation| and |toLocation| can be either
3030
// the name of a timezone (e.g. "UTC") or a MySQL-formatted timezone offset (e.g. "+01:00"). If the time was converted
3131
// successfully, then the second return value will be true, otherwise the time was not able to be converted.
32+
// TODO: This function relies on ConvertTimeToLocation functioning incorrectly to get the correct result. The resulting
33+
// time is still the same location as the original time, just with time values shifted.
3234
func ConvertTimeZone(datetime time.Time, fromLocation string, toLocation string) (time.Time, bool) {
3335
if fromLocation == toLocation {
3436
return datetime, true
@@ -97,6 +99,8 @@ func SecondsToMySQLOffset(offset int) string {
9799
// ConvertTimeToLocation converts |datetime| to the given |location|. |location| can be either the name of a timezone
98100
// (e.g. "UTC") or a MySQL-formatted timezone offset (e.g. "+01:00"). If the time was converted successfully, then
99101
// the converted time is returned, otherwise an error is returned.
102+
// TODO: this function does not work as expected. it takes the current time and converts it to what UTC would be if the
103+
// datetime is in the given location. The converted time also assumes UTC as its location.
100104
func ConvertTimeToLocation(datetime time.Time, location string) (time.Time, error) {
101105
// Try to load the timezone location string first
102106
loc, err := time.LoadLocation(location)

0 commit comments

Comments
 (0)