Compare date start/end.

This commit is contained in:
Tom Alexander
2023-10-02 15:59:06 -04:00
parent c55fae86f8
commit a8a34e2d9c
5 changed files with 115 additions and 46 deletions

View File

@@ -24,6 +24,9 @@ use crate::types::Clock;
use crate::types::Code;
use crate::types::Comment;
use crate::types::CommentBlock;
use crate::types::Date;
use crate::types::DayOfMonth;
use crate::types::DayOfMonthInner;
use crate::types::DiarySexp;
use crate::types::Document;
use crate::types::DocumentElement;
@@ -47,6 +50,8 @@ use crate::types::Keyword;
use crate::types::LatexEnvironment;
use crate::types::LatexFragment;
use crate::types::LineBreak;
use crate::types::Month;
use crate::types::MonthInner;
use crate::types::NodeProperty;
use crate::types::OrgMacro;
use crate::types::Paragraph;
@@ -81,6 +86,8 @@ use crate::types::TodoKeywordType;
use crate::types::Underline;
use crate::types::Verbatim;
use crate::types::VerseBlock;
use crate::types::Year;
use crate::types::YearInner;
#[derive(Debug)]
pub enum DiffEntry<'b, 's> {
@@ -2165,21 +2172,76 @@ fn compare_timestamp<'b, 's>(
}
// Compare start
let year_start: Option<u16> = get_property_unquoted_atom(emacs, ":year-start")?
.map(|val| val.parse())
.map_or(Ok(None), |r| r.map(Some))?;
let month_start: Option<u8> = get_property_unquoted_atom(emacs, ":month-start")?
.map(|val| val.parse())
.map_or(Ok(None), |r| r.map(Some))?;
let day_of_month_start: Option<u8> = get_property_unquoted_atom(emacs, ":day-start")?
.map(|val| val.parse())
.map_or(Ok(None), |r| r.map(Some))?;
let year_end = get_property_numeric::<u16>(emacs, ":year-end")?;
let year_start: Option<YearInner> = get_property_numeric(emacs, ":year-start")?;
let month_start: Option<MonthInner> = get_property_numeric(emacs, ":month-start")?;
let day_of_month_start: Option<DayOfMonthInner> = get_property_numeric(emacs, ":day-start")?;
let rust_year_start = rust.start.as_ref().map(Date::get_year).map(Year::get_value);
let rust_month_start = rust
.start
.as_ref()
.map(Date::get_month)
.map(Month::get_value);
let rust_day_of_month_start = rust
.start
.as_ref()
.map(Date::get_day_of_month)
.map(DayOfMonth::get_value);
if year_start != rust_year_start {
this_status = DiffStatus::Bad;
message = Some(format!(
"year start mismatch (emacs != rust) {:?} != {:?}",
year_start, rust_year_start
));
}
if month_start != rust_month_start {
this_status = DiffStatus::Bad;
message = Some(format!(
"month start mismatch (emacs != rust) {:?} != {:?}",
month_start, rust_month_start
));
}
if day_of_month_start != rust_day_of_month_start {
this_status = DiffStatus::Bad;
message = Some(format!(
"day of month start mismatch (emacs != rust) {:?} != {:?}",
day_of_month_start, rust_day_of_month_start
));
}
// Compare end
let year_end: Option<YearInner> = get_property_numeric(emacs, ":year-end")?;
let month_end: Option<MonthInner> = get_property_numeric(emacs, ":month-end")?;
let day_of_month_end: Option<DayOfMonthInner> = get_property_numeric(emacs, ":day-end")?;
let rust_year_end = rust.end.as_ref().map(Date::get_year).map(Year::get_value);
let rust_month_end = rust.end.as_ref().map(Date::get_month).map(Month::get_value);
let rust_day_of_month_end = rust
.end
.as_ref()
.map(Date::get_day_of_month)
.map(DayOfMonth::get_value);
if year_end != rust_year_end {
this_status = DiffStatus::Bad;
message = Some(format!(
"year end mismatch (emacs != rust) {:?} != {:?}",
year_end, rust_year_end
));
}
if month_end != rust_month_end {
this_status = DiffStatus::Bad;
message = Some(format!(
"month end mismatch (emacs != rust) {:?} != {:?}",
month_end, rust_month_end
));
}
if day_of_month_end != rust_day_of_month_end {
this_status = DiffStatus::Bad;
message = Some(format!(
"day of month end mismatch (emacs != rust) {:?} != {:?}",
day_of_month_end, rust_day_of_month_end
));
}
// TODO: Compare :year-start :month-start :day-start :hour-start :minute-start :year-end :month-end :day-end :hour-end :minute-end :repeater-type :repeater-value :repeater-unit :warning-type :warning-value :warning-unit
// TODO: Compare :hour-start :minute-start :hour-end :minute-end :repeater-type :repeater-value :repeater-unit :warning-type :warning-value :warning-unit
//
// :type unquoted atom either diary, active, inactive, active-range, or inactive-range.
// :range-type unquoted atom either nil, daterange

View File

@@ -248,11 +248,11 @@ where
<N as FromStr>::Err: std::error::Error,
<N as FromStr>::Err: 's,
{
let foo = get_property(emacs, key)?
let unparsed_string = get_property(emacs, key)?
.map(Token::as_atom)
.map_or(Ok(None), |r| r.map(Some))?;
let bar = foo
let parsed_number = unparsed_string
.map(|val| val.parse::<N>())
.map_or(Ok(None), |r| r.map(Some))?;
Ok(bar)
Ok(parsed_number)
}