| Crates.io | tdt |
| lib.rs | tdt |
| version | 0.3.1 |
| created_at | 2025-09-16 15:02:31.93071+00 |
| updated_at | 2025-09-25 16:54:47.228111+00 |
| description | Time Delta Toolkit (TDT): count ticks, breakdown intervals, pretty-print elapsed/remaining time. |
| homepage | |
| repository | https://github.com/JDPlumbing/tdt-rs |
| max_upload_size | |
| id | 1841896 |
| size | 39,270 |
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.
TimeDelta structchrono)from_now() — since epoch until nowbetween(start, end) — between two datetimesuntil_now(start) — from a given datetime until now.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"cargo add tdt
Or add manually to Cargo.toml:
[dependencies]
tdt = "0.1"
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
TimeDelta::from_now() -> TimeDeltaConstruct a delta from the epoch (1970-01-01 00:00:00 UTC) until now.
TimeDelta::between(start: DateTime<Utc>, end: DateTime<Utc>) -> TimeDeltaConstruct a delta between two arbitrary datetimes.
TimeDelta::until_now(start: DateTime<Utc>) -> TimeDeltaConstruct a delta from a given datetime until now.
TimeDelta::ticks(unit: &str) -> i64Return elapsed time in the specified unit. Supported:
"days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds"
TimeDelta::pretty(max_units: usize) -> StringReturn a human-readable string breakdown, up to max_units parts.
Run tests:
cargo test
Run benchmarks:
cargo bench
Format code:
cargo fmt
MIT © JD Plumbing