#date-time #chrono #time #date #humanize #arrow

chrono-humanize

Human-friendly time expressions - similar to Python arrow.humanize

18 releases

0.2.3 Jul 22, 2023
0.2.2 Aug 17, 2022
0.2.1 Apr 27, 2021
0.1.2 Feb 2, 2021
0.0.6 Jul 21, 2016

#15 in Date and time

Download history 16382/week @ 2023-12-23 22543/week @ 2023-12-30 31572/week @ 2024-01-06 29135/week @ 2024-01-13 30919/week @ 2024-01-20 25613/week @ 2024-01-27 28815/week @ 2024-02-03 22854/week @ 2024-02-10 28377/week @ 2024-02-17 28034/week @ 2024-02-24 27202/week @ 2024-03-02 26956/week @ 2024-03-09 29978/week @ 2024-03-16 29470/week @ 2024-03-23 32032/week @ 2024-03-30 28385/week @ 2024-04-06

123,548 downloads per month
Used in 398 crates (61 directly)

MIT/Apache

18KB
332 lines

Chrono Humanize - Make your text time representation human appealing

Build status

branch status
master Build Status
develop Build Status

Quick Start

use chrono::{Local, Duration};
use chrono_humanize::HumanTime;

let dt = Local::now() + Duration::days(35);
let ht = HumanTime::from(dt);
let english = format!("{}", ht);
assert_eq!("in a month", english);

lib.rs:

Representation for chrono objects in human languages

Quick Start

HumanTime objects are created from chrono objects, such as chrono::DateTime and chrono::Duration

Examples

Convert current time taken as Local::now() to HumanTime

let dt = chrono::Local::now();
let ht = chrono_humanize::HumanTime::from(dt);

assert_eq!("now", format!("{}", ht));
let dt = chrono::Local::now() - chrono::Duration::minutes(58);
let ht = chrono_humanize::HumanTime::from(dt);

assert_eq!("an hour ago", format!("{}", ht));

For full control over the text representation use HumanTime::to_text_en()

use chrono::Duration;
use chrono_humanize::{Accuracy, HumanTime, Tense};

let dt = Duration::days(45);
let ht = HumanTime::from(dt);

assert_eq!("a month", ht.to_text_en(Accuracy::Rough, Tense::Present));
assert_eq!("1 month, 2 weeks and 1 day", ht.to_text_en(Accuracy::Precise, Tense::Present));

Dependencies

~1–7.5MB
~27K SLoC