forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: Fix for invalid value for parameter "TimeZone": "GMT-08:00" cock…
…roachdb#41776 Previously, the inputs like `GMT+5` would cause error. Postgres supports inputs like this. So adding support for these inputs was necessary. sql: Added a check to convert the strings to offset. timeutil: added a function to convert input to offset seconds. Added unit tests. Added a regex to accept the inputs. Release note (sql change): `SET TIME ZONE` now accepts inputs mentioned in cockroachdb#41776. Now accepted time zone strings * `GMT+5` * `UTC-03:59:59`
- Loading branch information
Showing
4 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2019 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package timeutil | ||
|
||
import "testing" | ||
|
||
func TestTimeZoneOffsetStringConversion(t *testing.T) { | ||
testCases := []struct { | ||
timezone string | ||
offsetSecs int64 | ||
ok bool | ||
}{ | ||
{`GMT+00:00`, 0, true}, | ||
{`UTC-1:00:00`, -3600, true}, | ||
{`UTC+15:59`, 57540, true}, | ||
{`GMT-15:59:59`, -57599, true}, | ||
{`GMT-06:59`, -25140, true}, | ||
{`GMT+167:59:00`, 604740, true}, | ||
{`GMT+5`, 18000, true}, | ||
{`GMT-16`, -57600, true}, | ||
{`GMT-15:59:5Z`, 0, false}, | ||
{`GMT+6:00:0`, 0, false}, | ||
{`GMT+6:`, 0, false}, | ||
{`GMT-6:00:`, 0, false}, | ||
{`GMT+168:00:00`, 0, false}, | ||
{`GMT+6:0:59`, 0, false}, | ||
{`GMT-170:00:59`, 0, false}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
offset, ok := TimeZoneOffsetStringConversion(testCase.timezone) | ||
if offset != testCase.offsetSecs || ok != testCase.ok { | ||
t.Errorf("%d: Expected offset: %d, success: %v for time %s, but got offset: %d, success: %v", | ||
i, testCase.offsetSecs, testCase.ok, testCase.timezone, offset, ok) | ||
} | ||
} | ||
} |