#humanize #chrono #time #date #arrow

chrono-humanize

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

13 releases

0.1.1 Sep 15, 2020
0.1.0 Sep 15, 2020
0.0.11 Feb 5, 2018
0.0.10 Jun 23, 2017
0.0.6 Jul 21, 2016

#5 in Value formatting

Download history 3084/week @ 2020-06-09 6848/week @ 2020-06-16 9641/week @ 2020-06-23 8725/week @ 2020-06-30 9125/week @ 2020-07-07 9162/week @ 2020-07-14 9125/week @ 2020-07-21 9634/week @ 2020-07-28 9355/week @ 2020-08-04 9783/week @ 2020-08-11 9097/week @ 2020-08-18 8382/week @ 2020-08-25 8192/week @ 2020-09-01 7688/week @ 2020-09-08 7471/week @ 2020-09-15 8390/week @ 2020-09-22

37,962 downloads per month
Used in 23 crates (17 directly)

MIT/Apache

12KB
243 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};

# fn main() {
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

~1MB
~12K SLoC