use alloc::string::String;
use core::time::Duration;
pub trait MillisecondFormatter {
type Output;
fn pretty_with(&self, opt: MillisecondOption) -> Self::Output;
fn pretty(&self) -> Self::Output {
self.pretty_with(MillisecondOption::default())
}
#[deprecated(since = "0.4.0", note = "use the `pretty` instead")]
fn to_short_string(&self) -> Self::Output {
self.pretty()
}
#[deprecated(since = "0.4.0", note = "use the `pretty_with` function instead")]
fn to_long_string(&self) -> Self::Output {
self.pretty_with(MillisecondOption::long())
}
}
impl MillisecondFormatter for Duration {
type Output = String;
fn pretty_with(&self, opt: MillisecondOption) -> Self::Output {
let parts = super::parser::parse_duration(self, &opt);
super::parser::ms_parts_to_string(&parts, &opt)
}
}
#[derive(Debug, Copy, Clone, Default)]
pub struct MillisecondOption {
pub long: bool,
pub days_instead_of_years: bool,
pub dominant_only: bool,
pub format_sub_milliseconds: bool,
}
impl MillisecondOption {
pub fn long() -> Self {
Self {
long: true,
..Default::default()
}
}
pub fn sub_milliseconds() -> Self {
Self {
format_sub_milliseconds: true,
..Default::default()
}
}
}