#time

faketime

Fake time to ease testing and debugging

4 releases

0.2.1 Dec 17, 2020
0.2.0 Dec 21, 2018
0.1.1 Dec 20, 2018
0.1.0 Dec 20, 2018

#13 in Date and time

Download history 837/week @ 2021-02-21 554/week @ 2021-02-28 477/week @ 2021-03-07 530/week @ 2021-03-14 652/week @ 2021-03-21 643/week @ 2021-03-28 509/week @ 2021-04-04 885/week @ 2021-04-11 784/week @ 2021-04-18 963/week @ 2021-04-25 601/week @ 2021-05-02 1041/week @ 2021-05-09 1383/week @ 2021-05-16 1348/week @ 2021-05-23 522/week @ 2021-05-30 642/week @ 2021-06-06

2,931 downloads per month
Used in 30 crates (11 directly)

MIT license

13KB
148 lines

faketime

Build Status Build status

Provides a method unix_time which returns elapsed time since UNIX EPOCH. The returned time can be faked in each thread separately.

Documentation

Quick Start

Add faketime as dependency and use faketime::unix_time or faketime::unix_time_as_millis to get current time.

To fake time in test:

  • Use faketime::millis_tempfile to create a temp timestamp file.
  • Enable faketime via faketime::enable in current thread.

To fake time in child threads:

  • Use faketime::millis_tempfile to create a temp timestamp file.
  • Set child thread name to FAKETIME=PATH, where PATH is the path to the timestamp file.

To fake time of the generated binary, set the environment variable

echo 123456 > /tmp/faketime
FAKETIME=/tmp/faketime path/to/binary

Dependencies

~0–365KB