Skip to content

Commit

Permalink
fix(spanner/spansql): fix invalid timestamp literal formats (#6077)
Browse files Browse the repository at this point in the history
Co-authored-by: rahul2393 <rahulyadavsep92@gmail.com>
  • Loading branch information
neglect-yp and rahul2393 committed May 24, 2022
1 parent e823d8f commit 6ab8bed
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions spanner/spansql/parser.go
Expand Up @@ -3113,8 +3113,8 @@ var timestampFormats = []string{
"2006-01-02",
"2006-01-02 15:04:05",
"2006-01-02 15:04:05.000000",
"2006-01-02 15:04:05 -07:00",
"2006-01-02 15:04:05.000000 -07:00",
"2006-01-02 15:04:05-07:00",
"2006-01-02 15:04:05.000000-07:00",
}

var defaultLocation = func() *time.Location {
Expand Down
2 changes: 1 addition & 1 deletion spanner/spansql/sql.go
Expand Up @@ -736,7 +736,7 @@ func (dl DateLiteral) addSQL(sb *strings.Builder) {

func (tl TimestampLiteral) SQL() string { return buildSQL(tl) }
func (tl TimestampLiteral) addSQL(sb *strings.Builder) {
fmt.Fprintf(sb, "TIMESTAMP '%s'", time.Time(tl).Format("2006-01-02 15:04:05.000000 -07:00"))
fmt.Fprintf(sb, "TIMESTAMP '%s'", time.Time(tl).Format("2006-01-02 15:04:05.000000-07:00"))
}

func (jl JSONLiteral) SQL() string { return buildSQL(jl) }
Expand Down
2 changes: 1 addition & 1 deletion spanner/spansql/sql_test.go
Expand Up @@ -556,7 +556,7 @@ func TestSQL(t *testing.T) {
},
{
TimestampLiteral(time.Date(2014, time.September, 27, 12, 34, 56, 123456e3, latz)),
`TIMESTAMP '2014-09-27 12:34:56.123456 -07:00'`,
`TIMESTAMP '2014-09-27 12:34:56.123456-07:00'`,
reparseExpr,
},
{
Expand Down

0 comments on commit 6ab8bed

Please sign in to comment.