#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

#13 in Value formatting

Download history 893/week @ 2018-10-11 1465/week @ 2018-10-18 1341/week @ 2018-10-25 1281/week @ 2018-11-01 1159/week @ 2018-11-08 1165/week @ 2018-11-15 1123/week @ 2018-11-22 1531/week @ 2018-11-29 1497/week @ 2018-12-06 1344/week @ 2018-12-13 1216/week @ 2018-12-20 930/week @ 2018-12-27 758/week @ 2019-01-03

465 downloads per month
Used in 7 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

~743KB