#[derive(Default, Clone, Debug, Copy, PartialEq, Eq)]
pub enum LocalOrUTC {
#[default]
Local,
Utc,
}
#[derive(Default, Clone, Debug, Copy)]
pub struct Context {
pub(crate) verbose: Option<bool>,
pub(crate) max_items: Option<usize>,
pub(crate) local_or_utc: Option<LocalOrUTC>,
pub(crate) time_format: Option<&'static str>,
}
impl Context {
pub fn verbose(&self) -> bool {
self.verbose.unwrap_or(false)
}
pub fn max_items(&self) -> usize {
self.max_items.unwrap_or(32)
}
pub fn is_local_time(&self) -> bool {
self.local_or_utc.unwrap_or_default() == LocalOrUTC::Local
}
pub fn is_utc_time(&self) -> bool {
self.local_or_utc.unwrap_or_default() == LocalOrUTC::Utc
}
pub fn time_format(&self) -> &'static str {
const SIMPLE_FORMAT: &str = "%H:%M:%S%.6f";
const FULL_FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.6fZ%z";
match self.time_format {
Some("SIMPLE") => SIMPLE_FORMAT,
Some("FULL") => FULL_FORMAT,
Some(format) => format,
None => SIMPLE_FORMAT,
}
}
}