use alloc::string::ToString;
use crate::String;
macro_rules! impl_display {
($($name:ident),*) => {
paste::paste! {
$(
impl core::fmt::Display for [< $name s >] {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{} {}{}", self.value, stringify!([< $name:lower >]), if self.value != 1 { "s" } else { "" })
}
}
)*
}
};
}
impl_display!(Second, Minute, Hour, Day, Week, Month, Year);
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Seconds {
pub value: u64,
}
impl Seconds {
#[must_use]
pub fn format_if_nonzero(&self) -> Option<String> {
if self.is_zero() {
return None;
}
Some(self.to_string())
}
const fn is_zero(&self) -> bool {
self.value == 0
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Minutes {
pub value: u64,
}
impl Minutes {
#[must_use]
pub fn format_if_nonzero(&self) -> Option<String> {
if self.is_zero() {
return None;
}
Some(self.to_string())
}
const fn is_zero(&self) -> bool {
self.value == 0
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Hours {
pub value: u64,
}
impl Hours {
#[must_use]
pub fn format_if_nonzero(&self) -> Option<String> {
if self.is_zero() {
return None;
}
Some(self.to_string())
}
const fn is_zero(&self) -> bool {
self.value == 0
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Days {
pub value: u64,
}
impl Days {
#[must_use]
pub fn format_if_nonzero(&self) -> Option<String> {
if self.is_zero() {
return None;
}
Some(self.to_string())
}
const fn is_zero(&self) -> bool {
self.value == 0
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Weeks {
pub value: u64,
}
impl Weeks {
#[must_use]
pub fn format_if_nonzero(&self) -> Option<String> {
if self.is_zero() {
return None;
}
Some(self.to_string())
}
const fn is_zero(&self) -> bool {
self.value == 0
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Months {
pub value: u64,
}
impl Months {
#[must_use]
pub fn format_if_nonzero(&self) -> Option<String> {
if self.is_zero() {
return None;
}
Some(self.to_string())
}
const fn is_zero(&self) -> bool {
self.value == 0
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Years {
pub value: u64,
}
impl Years {
#[must_use]
pub fn format_if_nonzero(&self) -> Option<String> {
if self.is_zero() {
return None;
}
Some(self.to_string())
}
const fn is_zero(&self) -> bool {
self.value == 0
}
}