Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3732,7 +3732,7 @@ CREATE TABLE tab3 (
},
{
// When the session's time zone is set to UTC, NOW() and UTC_TIMESTAMP() should return the same value
Query: `select @@time_zone, NOW() = UTC_TIMESTAMP();`,
Query: `select @@time_zone, NOW(6) = UTC_TIMESTAMP();`,
Expected: []sql.Row{{"+00:00", true}},
},
{
Expand All @@ -3746,7 +3746,7 @@ CREATE TABLE tab3 (
},
{
// When the session's time zone is set to +2:00, NOW() should report two hours ahead of UTC_TIMESTAMP()
Query: `select @@time_zone, TIMESTAMPDIFF(MINUTE, NOW(), UTC_TIMESTAMP());`,
Query: `select @@time_zone, TIMESTAMPDIFF(MINUTE, NOW(6), UTC_TIMESTAMP());`,
Expected: []sql.Row{{"+02:00", -120}},
},
{
Expand Down
5 changes: 3 additions & 2 deletions sql/expression/function/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ func (n *Now) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
nano := precision * (t.Nanosecond() / precision)

// Generate a new timestamp
tt := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), nano, t.Location())
tt := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), nano, time.UTC)

return tt, nil
}
Expand Down Expand Up @@ -1099,7 +1099,8 @@ func (ut *UTCTimestamp) Children() []sql.Expression { return nil }
func (ut *UTCTimestamp) Eval(ctx *sql.Context, _ sql.Row) (interface{}, error) {
t := ctx.QueryTime()
// TODO: UTC Timestamp needs to also handle precision arguments
tt := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
nano := 1000 * (t.Nanosecond() / 1000)
tt := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), nano, t.Location())
return tt.UTC(), nil
}

Expand Down