#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

#10 in Value formatting

Download history 313/week @ 2018-05-05 509/week @ 2018-05-12 643/week @ 2018-05-19 577/week @ 2018-05-26 387/week @ 2018-06-02 507/week @ 2018-06-09 869/week @ 2018-06-16 1407/week @ 2018-06-23 669/week @ 2018-06-30 270/week @ 2018-07-07 777/week @ 2018-07-14 653/week @ 2018-07-21 423/week @ 2018-07-28

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

~749KB