tdt

Crates.iotdt
lib.rstdt
version0.3.1
created_at2025-09-16 15:02:31.93071+00
updated_at2025-09-25 16:54:47.228111+00
descriptionTime Delta Toolkit (TDT): count ticks, breakdown intervals, pretty-print elapsed/remaining time.
homepage
repositoryhttps://github.com/JDPlumbing/tdt-rs
max_upload_size
id1841896
size39,270
Dr.Ippy (JDPlumbing)

documentation

README

TDT (Time Delta Toolkit)

Crates.io Documentation License

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 TimeDelta struct
  • Nanosecond-level precision (via chrono)
  • Multiple constructors:
    • from_now() — since epoch until now
    • between(start, end) — between two datetimes
    • until_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

Commit count: 9

cargo fmt