• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.travis.ymlH A D18-Apr-201654

LICENSEH A D18-Apr-20161.1 KiB

README.mdH A D18-Apr-20161,017

clock.goH A D18-Apr-20166.1 KiB

clock_test.goH A D18-Apr-20168.2 KiB

timer.goH A D18-Apr-20161.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