use elicitation::elicit_newtype;
use elicitation_derive::reflect_methods;
use tracing::instrument;
elicit_newtype!(jiff::Zoned, as Zoned, serde);
#[reflect_methods]
impl Zoned {
#[instrument(skip(self))]
pub fn year(&self) -> i16 {
self.0.year()
}
#[instrument(skip(self))]
pub fn month(&self) -> i8 {
self.0.month()
}
#[instrument(skip(self))]
pub fn day(&self) -> i8 {
self.0.day()
}
#[instrument(skip(self))]
pub fn hour(&self) -> i8 {
self.0.hour()
}
#[instrument(skip(self))]
pub fn minute(&self) -> i8 {
self.0.minute()
}
#[instrument(skip(self))]
pub fn second(&self) -> i8 {
self.0.second()
}
#[instrument(skip(self))]
pub fn nanosecond(&self) -> i16 {
self.0.nanosecond()
}
#[instrument(skip(self))]
pub fn subsec_nanosecond(&self) -> i32 {
self.0.subsec_nanosecond()
}
#[instrument(skip(self))]
pub fn day_of_year(&self) -> i16 {
self.0.day_of_year()
}
#[instrument(skip(self))]
pub fn days_in_month(&self) -> i8 {
self.0.days_in_month()
}
#[instrument(skip(self))]
pub fn weekday(&self) -> String {
format!("{:?}", self.0.weekday())
}
#[instrument(skip(self))]
pub fn timezone_name(&self) -> String {
self.0.time_zone().iana_name().unwrap_or("UTC").to_string()
}
#[instrument(skip(self))]
pub fn timestamp_seconds(&self) -> i64 {
self.0.timestamp().as_second()
}
#[instrument(skip(self))]
pub fn in_tz(&self, name: String) -> Option<String> {
self.0.in_tz(&name).ok().map(|z| z.to_string())
}
}
impl Zoned {
pub fn now() -> Self {
jiff::Zoned::now().into()
}
pub fn parse(s: &str) -> Option<Self> {
s.parse::<jiff::Zoned>()
.ok()
.map(|z| std::sync::Arc::new(z).into())
}
}