#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 942/week @ 2018-12-20 879/week @ 2018-12-27 1316/week @ 2019-01-03 1340/week @ 2019-01-10 1258/week @ 2019-01-17 1405/week @ 2019-01-24 1556/week @ 2019-01-31 1357/week @ 2019-02-07 1261/week @ 2019-02-14 1705/week @ 2019-02-21 2212/week @ 2019-02-28 1772/week @ 2019-03-07 1638/week @ 2019-03-14 1619/week @ 2019-03-21 1741/week @ 2019-03-28

465 downloads per month
Used in 8 crates

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

~737KB