From 5d7fdeb5f7050a3eb22b0aaf79b8d372e74ed079 Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Fri, 30 Jun 2023 22:44:17 -0700 Subject: [PATCH 1/2] cleanup --- CHANGELOG.md | 7 ++++++- README.md | 2 +- time/instant.go | 12 +++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6d19c..ea7b575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [5.21.1] - 2023-06-30 +### Fixed +- Instant type to not be wrapped in a struct but a type itself. + ## [5.21.0] - 2023-06-30 ### Added - Instant type to make working with monotonically increasing times more convenient. @@ -66,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `timext.NanoTime` for fast low level monotonic time with nanosecond precision. -[Unreleased]: https://github.com/go-playground/pkg/compare/v5.21.0...HEAD +[Unreleased]: https://github.com/go-playground/pkg/compare/v5.21.1...HEAD +[5.21.0]: https://github.com/go-playground/pkg/compare/v5.21.0..v5.21.1 [5.21.0]: https://github.com/go-playground/pkg/compare/v5.20.0..v5.21.0 [5.20.0]: https://github.com/go-playground/pkg/compare/v5.19.0..v5.20.0 [5.19.0]: https://github.com/go-playground/pkg/compare/v5.18.0..v5.19.0 diff --git a/README.md b/README.md index b7ee92a..7cb7f19 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pkg -![Project status](https://img.shields.io/badge/version-5.21.0-green.svg) +![Project status](https://img.shields.io/badge/version-5.21.1-green.svg) [![Lint & Test](https://github.com/go-playground/pkg/actions/workflows/go.yml/badge.svg)](https://github.com/go-playground/pkg/actions/workflows/go.yml) [![Coverage Status](https://coveralls.io/repos/github/go-playground/pkg/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pkg?branch=master) [![GoDoc](https://godoc.org/github.com/go-playground/pkg?status.svg)](https://pkg.go.dev/mod/github.com/go-playground/pkg/v5) diff --git a/time/instant.go b/time/instant.go index 218f58a..8955458 100644 --- a/time/instant.go +++ b/time/instant.go @@ -8,24 +8,22 @@ import "time" // Instant represents a monotonic instant in time. // // Instants are opaque types that can only be compared with one another and allows measuring of duration. -type Instant struct { - monotonic int64 -} +type Instant int64 // NewInstant returns a new Instant. func NewInstant() Instant { - return Instant{monotonic: NanoTime()} + return Instant(NanoTime()) } // Elapsed returns the duration since the instant was created. func (i Instant) Elapsed() time.Duration { - return time.Duration(NanoTime() - i.monotonic) + return time.Duration(Instant(NanoTime()) - i) } // Since returns the duration elapsed from another Instant, or zero is that Instant is later than this one. func (i Instant) Since(instant Instant) time.Duration { - if instant.monotonic > i.monotonic { + if instant > i { return 0 } - return time.Duration(i.monotonic - instant.monotonic) + return time.Duration(i - instant) } From 0c02eae913c61e35ad1f935e31e0e934d6064522 Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Fri, 30 Jun 2023 22:52:27 -0700 Subject: [PATCH 2/2] use new --- time/instant.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/time/instant.go b/time/instant.go index 8955458..20c3d42 100644 --- a/time/instant.go +++ b/time/instant.go @@ -17,7 +17,7 @@ func NewInstant() Instant { // Elapsed returns the duration since the instant was created. func (i Instant) Elapsed() time.Duration { - return time.Duration(Instant(NanoTime()) - i) + return time.Duration(NewInstant() - i) } // Since returns the duration elapsed from another Instant, or zero is that Instant is later than this one.