5 unstable releases
| 0.3.1 | Sep 25, 2025 |
|---|---|
| 0.3.0 | Sep 23, 2025 |
| 0.2.1 | Sep 23, 2025 |
| 0.2.0 | Sep 17, 2025 |
| 0.1.0 | Sep 16, 2025 |
#191 in Date and time
60 downloads per month
Used in chronovox
12KB
171 lines
TDT (Time Delta Toolkit)
Time Delta Toolkit (TDT) — a tiny Rust library for measuring elapsed time between events.
Designed for simulations, games, and any system where you need fast, flexible time deltas.
✨ Features
- Simple API with the
TimeDeltastruct - Nanosecond-level precision (via
chrono) - Multiple constructors:
from_now()— since epoch until nowbetween(start, end)— between two datetimesuntil_now(start)— from a given datetime until now
- Utilities:
.ticks(unit)→ elapsed in a unit (days,hours,minutes,seconds,milliseconds,microseconds,nanoseconds).pretty(max_units)→ human-readable breakdown like"25 years, 3 months, 12 days"
📦 Installation
cargo add tdt
Or add manually to Cargo.toml:
[dependencies]
tdt = "0.1"
🔍 Example
use chrono::Utc;
use tdt::core::TimeDelta;
fn main() {
let start = Utc::now();
let td = TimeDelta::until_now(start);
println!("Elapsed (seconds): {}", td.ticks("seconds"));
println!("Pretty: {}", td.pretty(3));
}
Output:
Elapsed (seconds): 42
Pretty: 0 minutes, 42 seconds
📖 API
TimeDelta::from_now() -> TimeDelta
Construct a delta from the epoch (1970-01-01 00:00:00 UTC) until now.
TimeDelta::between(start: DateTime<Utc>, end: DateTime<Utc>) -> TimeDelta
Construct a delta between two arbitrary datetimes.
TimeDelta::until_now(start: DateTime<Utc>) -> TimeDelta
Construct a delta from a given datetime until now.
TimeDelta::ticks(unit: &str) -> i64
Return elapsed time in the specified unit. Supported:
"days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds"
TimeDelta::pretty(max_units: usize) -> String
Return a human-readable string breakdown, up to max_units parts.
🛠 Development
Run tests:
cargo test
Run benchmarks:
cargo bench
Format code:
cargo fmt
📎 Links
📄 License
MIT © JD Plumbing
Dependencies
~2–3MB
~56K SLoC