use serde::Deserialize; use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; use crate::compare::ElispFact; use crate::types::DayOfMonthInner; use crate::types::HourInner; use crate::types::MinuteInner; use crate::types::MonthInner; use crate::types::RepeaterType; use crate::types::RepeaterWarningDelayValueType; use crate::types::TimeUnit; use crate::types::Timestamp; use crate::types::TimestampRangeType; use crate::types::TimestampType; use crate::types::WarningDelayType; use crate::types::YearInner; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] pub struct WasmTimestamp { #[serde(rename = "type")] pub(crate) timestamp_type: String, #[serde(rename = "range-type")] pub(crate) range_type: Option, #[serde(rename = "raw-value")] pub(crate) raw_value: String, #[serde(rename = "year-start")] pub(crate) year_start: Option, #[serde(rename = "month-start")] pub(crate) month_start: Option, #[serde(rename = "day-start")] pub(crate) day_of_month_start: Option, #[serde(rename = "hour-start")] pub(crate) hour_start: Option, #[serde(rename = "minute-start")] pub(crate) minute_start: Option, #[serde(rename = "year-end")] pub(crate) year_end: Option, #[serde(rename = "month-end")] pub(crate) month_end: Option, #[serde(rename = "day-end")] pub(crate) day_of_month_end: Option, #[serde(rename = "hour-end")] pub(crate) hour_end: Option, #[serde(rename = "minute-end")] pub(crate) minute_end: Option, #[serde(rename = "repeater-type")] pub(crate) repeater_type: Option, #[serde(rename = "repeater-unit")] pub(crate) repeater_unit: Option, #[serde(rename = "repeater-value")] pub(crate) repeater_value: Option, #[serde(rename = "warning-type")] pub(crate) warning_type: Option, #[serde(rename = "warning-unit")] pub(crate) warning_unit: Option, #[serde(rename = "warning-value")] pub(crate) warning_value: Option, } to_wasm!( WasmTimestamp, Timestamp<'s>, original, wasm_context, { WasmAstNode::Timestamp(original) }, { "timestamp".into() }, { Ok(( Vec::new(), WasmTimestamp { timestamp_type: match original.timestamp_type { TimestampType::Diary => "diary", TimestampType::Active => "active", TimestampType::Inactive => "inactive", TimestampType::ActiveRange => "active-range", TimestampType::InactiveRange => "inactive-range", } .to_owned(), range_type: match original.range_type { TimestampRangeType::DateRange => Some("daterange".to_owned()), TimestampRangeType::TimeRange => Some("timerange".to_owned()), TimestampRangeType::None => None, }, raw_value: original.get_raw_value().to_owned(), year_start: original.start.as_ref().map(|date| date.get_year().0), month_start: original.start.as_ref().map(|date| date.get_month().0), day_of_month_start: original .start .as_ref() .map(|date| date.get_day_of_month().0), hour_start: original.start_time.as_ref().map(|time| time.get_hour().0), minute_start: original.start_time.as_ref().map(|time| time.get_minute().0), year_end: original.end.as_ref().map(|date| date.get_year().0), month_end: original.end.as_ref().map(|date| date.get_month().0), day_of_month_end: original.end.as_ref().map(|date| date.get_day_of_month().0), hour_end: original.end_time.as_ref().map(|time| time.get_hour().0), minute_end: original.end_time.as_ref().map(|time| time.get_minute().0), repeater_type: original .repeater .as_ref() .map(|repeater| match repeater.repeater_type { RepeaterType::Cumulative => "cumulate", RepeaterType::CatchUp => "catch-up", RepeaterType::Restart => "restart", }) .map(|text| text.to_owned()), repeater_unit: original .repeater .as_ref() .map(|repeater| match repeater.unit { TimeUnit::Hour => "hour", TimeUnit::Day => "day", TimeUnit::Week => "week", TimeUnit::Month => "month", TimeUnit::Year => "year", }) .map(|text| text.to_owned()), repeater_value: original.repeater.as_ref().map(|repeater| repeater.value), warning_type: original .warning_delay .as_ref() .map(|warning| match warning.warning_delay_type { WarningDelayType::All => "all", WarningDelayType::First => "first", }) .map(|text| text.to_owned()), warning_unit: original .warning_delay .as_ref() .map(|warning| match warning.unit { TimeUnit::Hour => "hour", TimeUnit::Day => "day", TimeUnit::Week => "week", TimeUnit::Month => "month", TimeUnit::Year => "year", }) .map(|text| text.to_owned()), warning_value: original.warning_delay.as_ref().map(|warning| warning.value), }, )) } );