Skip to content

Commit f976144

Browse files
committed
allow SYSTEM as valid time zone
1 parent 160be11 commit f976144

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

enginetest/queries/time_queries.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,22 @@ var TimeQueryTests = []ScriptTest{
8080
},
8181
},
8282
},
83+
{
84+
Name: "set timezone to SYSTEM",
85+
SetUpScript: []string{},
86+
Assertions: []ScriptTestAssertion{
87+
{
88+
Query: "select @@time_zone",
89+
Expected: []sql.Row{{"SYSTEM"}},
90+
},
91+
{
92+
Query: "set @old_time_zone=@@time_zone",
93+
Expected: []sql.Row{{types.NewOkResult(0)}},
94+
},
95+
{
96+
Query: "set @@time_zone=@old_time_zone",
97+
Expected: []sql.Row{{types.NewOkResult(0)}},
98+
},
99+
},
100+
},
83101
}

sql/rowexec/rel_iters.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ package rowexec
1616

1717
import (
1818
"errors"
19-
"io"
20-
"strings"
21-
"time"
22-
2319
"github.com/dolthub/go-mysql-server/sql"
2420
"github.com/dolthub/go-mysql-server/sql/expression"
2521
"github.com/dolthub/go-mysql-server/sql/expression/function/aggregation"
@@ -28,6 +24,8 @@ import (
2824
"github.com/dolthub/go-mysql-server/sql/plan"
2925
"github.com/dolthub/go-mysql-server/sql/transform"
3026
"github.com/dolthub/go-mysql-server/sql/types"
27+
"io"
28+
"strings"
3129
)
3230

3331
// windowToIter transforms a plan.Window into a series
@@ -476,11 +474,7 @@ func validateSystemVariableValue(sysVarName string, val interface{}) error {
476474
if !ok {
477475
return sql.ErrInvalidTimeZone.New(val)
478476
}
479-
_, err := time.LoadLocation(valStr)
480-
if err == nil {
481-
return nil
482-
}
483-
if !sql.ValidTimeOffset(valStr) {
477+
if !sql.ValidTimeZone(valStr) {
484478
return sql.ErrInvalidTimeZone.New(valStr)
485479
}
486480
}

sql/time.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"math"
2121
"regexp"
22+
"strings"
2223
"time"
2324
)
2425

@@ -47,8 +48,12 @@ func ConvertTimeZone(datetime time.Time, fromLocation string, toLocation string)
4748
return datetime.Add(delta), true
4849
}
4950

50-
func ValidTimeOffset(str string) bool {
51-
return offsetRegex.MatchString(str)
51+
func ValidTimeZone(str string) bool {
52+
_, err := time.LoadLocation(str)
53+
if err == nil {
54+
return true
55+
}
56+
return offsetRegex.MatchString(str) || strings.ToUpper(str) == "SYSTEM"
5257
}
5358

5459
// MySQLOffsetToDuration takes in a MySQL timezone offset (e.g. "+01:00") and returns it as a time.Duration.

0 commit comments

Comments
 (0)