mod format;
mod interval;
mod options;
use jiff::Zoned;
pub use format::{append_interval, format_interval};
pub use interval::{diff, Interval};
pub use options::{Config, Options, Syntax, Unit};
pub fn diff_for_humans(from: &Zoned, to: &Zoned, cfg: Config) -> String {
let mut s = String::with_capacity(48);
append_diff_for_humans(&mut s, from, to, cfg);
s
}
#[inline]
pub fn append_diff_for_humans(out: &mut String, from: &Zoned, to: &Zoned, cfg: Config) {
append_interval(out, diff(from, to), cfg)
}
#[derive(Clone, Debug)]
pub struct Formatter {
now: Zoned,
cfg: Config,
}
impl Formatter {
pub fn new(now: Zoned, mut cfg: Config) -> Self {
if cfg.syntax == Syntax::RelativeAuto {
cfg.syntax = Syntax::RelativeToNow;
}
Self { now, cfg }
}
pub fn reference(&self) -> &Zoned {
&self.now
}
pub fn format(&self, from: &Zoned) -> String {
format_interval(diff(from, &self.now), self.cfg)
}
#[inline]
pub fn append_format(&self, out: &mut String, from: &Zoned) {
append_interval(out, diff(from, &self.now), self.cfg)
}
}