humantime_fmt

Crates.iohumantime_fmt
lib.rshumantime_fmt
version0.1.0
created_at2025-07-01 20:24:48.1634+00
updated_at2025-07-01 20:24:48.1634+00
descriptionA simple human-readable time formatter for durations and timestamps.
homepage
repositoryhttps://github.com/haffizaliraza/humantime_fmt
max_upload_size
id1733758
size1,406,196
Hafiz Ali Raza (ar7kingcodedev)

documentation

https://docs.rs/humantime_fmt

README

humantime_fmt

A lightweight Rust crate to convert durations or timestamps into human-friendly strings.

✅ Features

  • Convert durations or timestamps into human-friendly strings
  • Support for relative times in past and future
  • Granular outputs like:
    • "just now"
    • "5 minutes ago"
    • "2 hours ago"
    • "yesterday"
    • "last week"
    • "in 3 days"
    • "next week"

🚀 Usage Example

use humantime_fmt::format_relative;
use std::time::{SystemTime, Duration};

let now = SystemTime::now();
let past = now - Duration::from_secs(60 * 60 * 24);  // 1 day ago
let future = now + Duration::from_secs(60 * 60 * 24 * 7);  // in 1 week

assert_eq!(format_relative(past), "yesterday");
assert_eq!(format_relative(future), "in 1 week");

🔧 Installation

humantime_fmt = "0.1"

For chrono support:

humantime_fmt = { version = "0.1", features = ["chrono"] }

📃 License

Licensed under either of:

  • MIT License
  • Apache License 2.0
Commit count: 0

cargo fmt