#date-time #time #date #chrono #humanize #arrow

chrono-humanize

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

18 releases

0.2.3 Jul 22, 2023
0.2.2 Aug 17, 2022
0.2.1 Apr 27, 2021
0.1.2 Feb 2, 2021
0.0.6 Jul 21, 2016

#18 in Date and time

Download history 30951/week @ 2024-07-21 29698/week @ 2024-07-28 30916/week @ 2024-08-04 28861/week @ 2024-08-11 28376/week @ 2024-08-18 30448/week @ 2024-08-25 26224/week @ 2024-09-01 27904/week @ 2024-09-08 17199/week @ 2024-09-15 25966/week @ 2024-09-22 24608/week @ 2024-09-29 26194/week @ 2024-10-06 31317/week @ 2024-10-13 30312/week @ 2024-10-20 33894/week @ 2024-10-27 32096/week @ 2024-11-03

129,706 downloads per month
Used in 476 crates (65 directly)

MIT/Apache

18KB
332 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};

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

~1–6MB
~26K SLoC