Skip to content

Commit ef3be41

Browse files
author
Dean Karn
authored
Fix Instant to be a type not struct. (#37)
1 parent 9a02754 commit ef3be41

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [5.21.1] - 2023-06-30
10+
### Fixed
11+
- Instant type to not be wrapped in a struct but a type itself.
12+
913
## [5.21.0] - 2023-06-30
1014
### Added
1115
- 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
6670
### Added
6771
- Added `timext.NanoTime` for fast low level monotonic time with nanosecond precision.
6872

69-
[Unreleased]: https://github.com/go-playground/pkg/compare/v5.21.0...HEAD
73+
[Unreleased]: https://github.com/go-playground/pkg/compare/v5.21.1...HEAD
74+
[5.21.0]: https://github.com/go-playground/pkg/compare/v5.21.0..v5.21.1
7075
[5.21.0]: https://github.com/go-playground/pkg/compare/v5.20.0..v5.21.0
7176
[5.20.0]: https://github.com/go-playground/pkg/compare/v5.19.0..v5.20.0
7277
[5.19.0]: https://github.com/go-playground/pkg/compare/v5.18.0..v5.19.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pkg
22

3-
![Project status](https://img.shields.io/badge/version-5.21.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-5.21.1-green.svg)
44
[![Lint & Test](https://github.com/go-playground/pkg/actions/workflows/go.yml/badge.svg)](https://github.com/go-playground/pkg/actions/workflows/go.yml)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/pkg/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pkg?branch=master)
66
[![GoDoc](https://godoc.org/github.com/go-playground/pkg?status.svg)](https://pkg.go.dev/mod/github.com/go-playground/pkg/v5)

time/instant.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,22 @@ import "time"
88
// Instant represents a monotonic instant in time.
99
//
1010
// Instants are opaque types that can only be compared with one another and allows measuring of duration.
11-
type Instant struct {
12-
monotonic int64
13-
}
11+
type Instant int64
1412

1513
// NewInstant returns a new Instant.
1614
func NewInstant() Instant {
17-
return Instant{monotonic: NanoTime()}
15+
return Instant(NanoTime())
1816
}
1917

2018
// Elapsed returns the duration since the instant was created.
2119
func (i Instant) Elapsed() time.Duration {
22-
return time.Duration(NanoTime() - i.monotonic)
20+
return time.Duration(NewInstant() - i)
2321
}
2422

2523
// Since returns the duration elapsed from another Instant, or zero is that Instant is later than this one.
2624
func (i Instant) Since(instant Instant) time.Duration {
27-
if instant.monotonic > i.monotonic {
25+
if instant > i {
2826
return 0
2927
}
30-
return time.Duration(i.monotonic - instant.monotonic)
28+
return time.Duration(i - instant)
3129
}

0 commit comments

Comments
 (0)