https://github.com/bep/clocks
A Golang clock that allows you to set the start time.
https://github.com/bep/clocks
Last synced: about 1 year ago
JSON representation
A Golang clock that allows you to set the start time.
- Host: GitHub
- URL: https://github.com/bep/clocks
- Owner: bep
- License: mit
- Created: 2022-05-06T15:25:20.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-09T10:22:39.000Z (almost 2 years ago)
- Last Synced: 2025-02-28T13:48:51.240Z (about 1 year ago)
- Language: Go
- Size: 21.5 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/bep/clocks/actions?query=workflow:Test)
[](https://goreportcard.com/report/github.com/bep/clocks)
[](https://godoc.org/github.com/bep/clocks)
This package provides a _ticking clock_ that allows you to set the start time. It also provides a system clock and a fixed clock, all implementing this interface:
```go
// Clock provides the sub set of methods in time.Time that this package provides.
type Clock interface {
Now() time.Time
Since(t time.Time) time.Duration
Until(t time.Time) time.Duration
// Offset returns the offset of this clock relative to the system clock.
Offset() time.Duration
}
```
Note that this only support a subset of all the methods in `time.Time` (see above) and is by design very simple. If you're looking for a more advanced time mocking library, have a look at https://github.com/benbjohnson/clock.