Skip to content

Commit

Permalink
util: fix GetTimeZoneOffset error when migrating repo (#33562)
Browse files Browse the repository at this point in the history
ref #32999
  • Loading branch information
lance6716 authored Mar 29, 2022
1 parent 762ae26 commit fbaaa11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 1 addition & 3 deletions util/dbutil/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,7 @@ func GetTimeZoneOffset(ctx context.Context, db QueryExecutor) (time.Duration, er

hour, minute, second := t.Clock()
// nolint:durationcheck
return (time.Duration(hour)*time.Hour +
time.Duration(minute)*time.Minute +
time.Duration(second)*time.Second) * factor * time.Second, nil
return time.Duration(hour*3600+minute*60+second) * time.Second * factor, nil
}

// FormatTimeZoneOffset is to format offset of timezone.
Expand Down
11 changes: 11 additions & 0 deletions util/dbutil/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,14 @@ func TestFormatTimeZoneOffset(t *testing.T) {
require.Equal(t, offset, k)
}
}

func TestGetTimeZoneOffset(t *testing.T) {
db, mock, err := sqlmock.New()
require.NoError(t, err)

mock.ExpectQuery("SELECT cast\\(TIMEDIFF\\(NOW\\(6\\), UTC_TIMESTAMP\\(6\\)\\) as time\\);").
WillReturnRows(mock.NewRows([]string{""}).AddRow("01:00:00"))
d, err := GetTimeZoneOffset(context.Background(), db)
require.NoError(t, err)
require.Equal(t, "1h0m0s", d.String())
}

0 comments on commit fbaaa11

Please sign in to comment.