Crate jiffy

Source
Expand description

Representation for jiff objects in human languages

§Quick Start

HumanTime objects are created from jiff objects, such as jiff::DateTime and jiff::Span

§Examples

Convert current time taken as now to HumanTime

let dt = jiff::Zoned::now();
let ht = jiffy::HumanTime::from(dt);

assert_eq!("now", format!("{}", ht));
let dt = jiff::Zoned::now().checked_sub(58.minutes()).unwrap()
let ht = jiffy::HumanTime::from(dt);

assert_eq!("an hour ago", format!("{}", ht));

For full control over the text representation use HumanTime::to_text_en()

use jiff::ToSpan;;
use jiffy::{Accuracy, HumanTime, Tense};

let dt = 45.days();
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));

Structs§

HumanTime
Duration wrapper that helps expressing the duration in human languages

Enums§

Accuracy
The accuracy of the representation
Tense
Indicates the time of the period in relation to the time of the utterance

Traits§

Humanize
Present the object in human friendly text form