Skip to content

Commit

Permalink
timeutil: remove detritus windows Now() implementation
Browse files Browse the repository at this point in the history
We carried a custom implementation of timeutil.Now() for Windows, to
overcome the low precision of Go's implementation [1]. Our
implementation was expensive, though. Having this custom implementation
also makes it tricky to use stdlib functions like Since(), which
internally use the stdlib Now().
The Golang issue has since been fixed, so our custom implementation can
go away.

[1] golang/go#8687

Release note: None
  • Loading branch information
andreimatei committed Nov 11, 2021
1 parent 1072ae4 commit 94cfb6c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 71 deletions.
2 changes: 0 additions & 2 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,6 @@ func TestLint(t *testing.T) {
"--",
"*.go",
":!**/embedded.go",
":!util/timeutil/now_unix.go",
":!util/timeutil/now_windows.go",
":!util/timeutil/time.go",
":!util/timeutil/zoneinfo.go",
":!util/tracing/span.go",
Expand Down
9 changes: 1 addition & 8 deletions pkg/util/timeutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ go_library(
name = "timeutil",
srcs = [
"manual_time.go",
"now_unix.go",
"now_windows.go",
"stopwatch.go",
"time.go",
"time_source.go",
Expand All @@ -20,12 +18,7 @@ go_library(
deps = [
"//pkg/util/syncutil",
"@com_github_cockroachdb_errors//:errors",
] + select({
"@io_bazel_rules_go//go/platform:windows": [
"@org_golang_x_sys//windows",
],
"//conditions:default": [],
}),
],
)

go_test(
Expand Down
21 changes: 0 additions & 21 deletions pkg/util/timeutil/now_unix.go

This file was deleted.

40 changes: 0 additions & 40 deletions pkg/util/timeutil/now_windows.go

This file was deleted.

5 changes: 5 additions & 0 deletions pkg/util/timeutil/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
// LibPQTimePrefix is the prefix lib/pq prints time-type datatypes with.
const LibPQTimePrefix = "0000-01-01"

// Now returns the current UTC time.
func Now() time.Time {
return time.Now().UTC()
}

// Since returns the time elapsed since t.
// It is shorthand for Now().Sub(t).
func Since(t time.Time) time.Duration {
Expand Down

0 comments on commit 94cfb6c

Please sign in to comment.