Implement timestamp.

This commit is contained in:
Tom Alexander 2023-12-29 20:55:01 -05:00
parent 34b3e4fa7b
commit 83e4b72307
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 123 additions and 10 deletions

View File

@ -332,19 +332,19 @@ pub type HourInner = u8;
pub type MinuteInner = u8;
#[derive(Debug, Clone)]
pub struct Year(YearInner);
pub struct Year(pub YearInner);
#[derive(Debug, Clone)]
pub struct Month(MonthInner);
pub struct Month(pub MonthInner);
#[derive(Debug, Clone)]
pub struct DayOfMonth(DayOfMonthInner);
pub struct DayOfMonth(pub DayOfMonthInner);
#[derive(Debug, Clone)]
pub struct Hour(HourInner);
pub struct Hour(pub HourInner);
#[derive(Debug, Clone)]
pub struct Minute(MinuteInner);
pub struct Minute(pub MinuteInner);
impl Year {
// TODO: Make a real error type instead of a boxed any error.

View File

@ -4,15 +4,61 @@ use serde::Serialize;
use super::ast_node::WasmAstNode;
use super::macros::to_wasm;
use super::to_wasm::ToWasm;
use super::AdditionalProperties;
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(flatten)]
pub(crate) additional_properties: AdditionalProperties,
#[serde(rename = "type")]
pub(crate) timestamp_type: String,
#[serde(rename = "range-type")]
pub(crate) range_type: Option<String>,
#[serde(rename = "raw-value")]
pub(crate) raw_value: String,
#[serde(rename = "year-start")]
pub(crate) year_start: Option<YearInner>,
#[serde(rename = "month-start")]
pub(crate) month_start: Option<MonthInner>,
#[serde(rename = "day-start")]
pub(crate) day_of_month_start: Option<DayOfMonthInner>,
#[serde(rename = "hour-start")]
pub(crate) hour_start: Option<HourInner>,
#[serde(rename = "minute-start")]
pub(crate) minute_start: Option<MinuteInner>,
#[serde(rename = "year-end")]
pub(crate) year_end: Option<YearInner>,
#[serde(rename = "month-end")]
pub(crate) month_end: Option<MonthInner>,
#[serde(rename = "day-end")]
pub(crate) day_of_month_end: Option<DayOfMonthInner>,
#[serde(rename = "hour-end")]
pub(crate) hour_end: Option<HourInner>,
#[serde(rename = "minute-end")]
pub(crate) minute_end: Option<MinuteInner>,
#[serde(rename = "repeater-type")]
pub(crate) repeater_type: Option<String>,
#[serde(rename = "repeater-unit")]
pub(crate) repeater_unit: Option<String>,
#[serde(rename = "repeater-value")]
pub(crate) repeater_value: Option<RepeaterWarningDelayValueType>,
#[serde(rename = "warning-type")]
pub(crate) warning_type: Option<String>,
#[serde(rename = "warning-unit")]
pub(crate) warning_unit: Option<String>,
#[serde(rename = "warning-value")]
pub(crate) warning_value: Option<RepeaterWarningDelayValueType>,
}
to_wasm!(
@ -21,12 +67,79 @@ to_wasm!(
original,
wasm_context,
{ WasmAstNode::Timestamp(original) },
{ "TODO".into() },
{ "timestamp".into() },
{
Ok((
Vec::new(),
WasmTimestamp {
additional_properties: AdditionalProperties::default(),
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),
},
))
}