https://github.com/anothermemory/clock
Simple clock library that can be mocked for testing if needed
https://github.com/anothermemory/clock
clock go golang mock time
Last synced: 5 months ago
JSON representation
Simple clock library that can be mocked for testing if needed
- Host: GitHub
- URL: https://github.com/anothermemory/clock
- Owner: anothermemory
- License: apache-2.0
- Created: 2018-01-03T22:58:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-20T15:54:39.000Z (over 8 years ago)
- Last Synced: 2024-06-20T00:38:23.295Z (about 2 years ago)
- Topics: clock, go, golang, mock, time
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Another Memory Clock
[](https://goreportcard.com/report/github.com/anothermemory/clock)
[](http://godoc.org/github.com/anothermemory/clock)
[](https://coveralls.io/github/anothermemory/clock)
[](https://github.com/anothermemory/clock/releases/latest)
[](LICENSE.md)
[](https://www.codacy.com/app/anothermemory/clock)
This library contains interface and set of implementations for getting current time. For production usage
time must be mostly real time. For testing purposes it's often much easier to use mocked time so it will
return required time each time.
Table of Contents
=================
* [Another Memory Clock](#another-memory-clock)
* [Table of Contents](#table-of-contents)
* [Getting Started](#getting-started)
* [Prerequisites](#prerequisites)
* [Installing](#installing)
* [See it in action](#see-it-in-action)
* [Mocked clock for testing](#mocked-clock-for-testing)
* [Real clock for production](#real-clock-for-production)
* [Built With](#built-with)
* [Contributing](#contributing)
* [Versioning](#versioning)
* [Authors](#authors)
* [License](#license)
## Getting Started
### Prerequisites
The project is tested with go 1.9 but probably will work with earlier versions.
### Installing
Simple go get it
```bash
go get github.com/anothermemory/clock
```
### See it in action
#### Mocked clock for testing
```go
package clock_test
import (
"time"
"github.com/anothermemory/clock"
)
func ExampleMock() {
var dummyTime = time.Date(2017, 11, 24, 17, 0, 0, 0, time.Local)
c := clock.NewMock(dummyTime)
c.Now() // Will return dummyTime each time
}
func ExampleMockPartial() {
firstTime := time.Date(2017, 11, 24, 17, 0, 0, 0, time.Local)
secondTime := time.Date(2018, 11, 24, 17, 0, 0, 0, time.Local)
c := clock.NewMockPartial(firstTime, secondTime)
c.Now() // This will return firstTime
c.Now() // This will return secondTime
c.Now() // This will return real time
}
```
#### Real clock for production
```go
package clock_test
import (
"time"
"github.com/anothermemory/clock"
)
func ExampleReal() {
c := clock.NewReal()
c.Now() // Will return real current time
}
```
## Built With
* [dep](https://github.com/golang/dep) - The dependency management tool for Go
## Contributing
Please read [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for details on our code of conduct, and [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for submitting pull requests to us.
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/anothermemory/clock/tags).
## Authors
* **Vyacheslav Enis**
See also the list of [contributors](https://github.com/anothermemory/clock/contributors) who participated in this project.
## License
This project is licensed under the Apache License 2.0 - see the [LICENSE.md](LICENSE.md) file for details