Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.travis.yml | H A D | 18-Apr-2016 | 54 | |||
LICENSE | H A D | 18-Apr-2016 | 1.1 KiB | |||
README.md | H A D | 18-Apr-2016 | 1,017 | |||
clock.go | H A D | 18-Apr-2016 | 6.1 KiB | |||
clock_test.go | H A D | 18-Apr-2016 | 8.2 KiB | |||
timer.go | H A D | 18-Apr-2016 | 1.3 KiB |
README.md
1clock 2==== 3 4[![Build Status](https://travis-ci.org/jmhodges/clock.png?branch=master)](https://travis-ci.org/jmhodges/clock) 5 6Package clock provides an abstraction for system time that enables 7testing of time-sensitive code. 8 9Where you'd use time.Now, instead use clk.Now where clk is an instance 10of Clock. 11 12When running your code in production, pass it a Clock given by 13Default() and when you're running it in your tests, pass it an instance of Clock from NewFake(). 14 15When you do that, you can use FakeClock's Add and Set methods to 16control how time behaves in your code making them more reliable while 17also expanding the space of problems you can test. 18 19This code intentionally does not attempt to provide an abstraction 20over time.Ticker and time.Timer because Go does not have the runtime 21or API hooks available to do reliably. See 22https://github.com/golang/go/issues/8869 23 24Be sure to test Time equality with time.Time#Equal, not ==. 25 26For documentation, see the 27[godoc](http://godoc.org/github.com/jmhodges/clock). 28