#humanize #chrono #time #date #arrow

chrono-humanize

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

11 releases

0.0.11 Feb 5, 2018
0.0.10 Jun 23, 2017
0.0.9 May 2, 2017
0.0.8 Feb 8, 2017
0.0.6 Jul 21, 2016

#16 in Value formatting

Download history 4226/week @ 2019-12-02 3543/week @ 2019-12-09 3134/week @ 2019-12-16 1949/week @ 2019-12-23 2346/week @ 2019-12-30 3525/week @ 2020-01-06 2577/week @ 2020-01-13 2487/week @ 2020-01-20 4036/week @ 2020-01-27 3900/week @ 2020-02-03 2696/week @ 2020-02-10 2826/week @ 2020-02-17 3437/week @ 2020-02-24 3215/week @ 2020-03-02 3357/week @ 2020-03-09 3745/week @ 2020-03-16

13,377 downloads per month
Used in 11 crates (10 directly)

MIT/Apache

12KB
230 lines

Chrono Humanize - Make your text time representation human appealing

Build status

branch status
master Build Status
develop Build Status

Quick Start

extern crate chrono;
extern crate chrono_humanize;

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

extern crate chrono;
extern crate chrono_humanize;

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

assert_eq!("now", format!("{}", ht));
extern crate chrono;
extern crate chrono_humanize;

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()

extern crate chrono;
extern crate chrono_humanize;

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

~770KB
~10K SLoC