#testing #time #mocking #chrono #traits #interface #utc-clock

clockabilly

Trait wrapper around chrono for testing

2 releases

0.1.1 Jul 17, 2024
0.1.0 Jul 17, 2024

#204 in Date and time

Download history 62/week @ 2024-09-01 21/week @ 2024-09-08 82/week @ 2024-09-15 82/week @ 2024-09-22 115/week @ 2024-09-29 58/week @ 2024-10-06 31/week @ 2024-10-13 85/week @ 2024-10-20 134/week @ 2024-10-27 82/week @ 2024-11-03 43/week @ 2024-11-10 128/week @ 2024-11-17 57/week @ 2024-11-24 9/week @ 2024-12-01

237 downloads per month
Used in 7 crates

MIT license

28KB
58 lines

Clockabilly

an AI-generated bird with gears and a clock in its belly

A really simple trait wrapper for chrono that lets you mock out time in tests.

Usage

Any place you want to mock time, you need to pass in a Clockable interface. In your "real" code you can use a UtcClock, and in your testing code you can use a MockUtcClock (you need to include the mock feature for this). See the basic example for an example:

> cargo run --example basic --features=mock
   Compiling clockabilly v0.0.0 (/build/src/clockabilly)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/examples/basic`
2024-07-17T17:41:02.369894602Z
1970-01-01T00:00:10Z

For "simplicity", this re-exports all of chrono.

Dependencies

~1MB
~18K SLoC