start the ical formatter
This commit is contained in:
parent
9fb45502a8
commit
a6ee7aea5f
|
@ -11,6 +11,7 @@ pub mod text;
|
||||||
pub mod csv;
|
pub mod csv;
|
||||||
pub mod json;
|
pub mod json;
|
||||||
pub mod ids;
|
pub mod ids;
|
||||||
|
pub mod ical;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
|
@ -19,6 +20,7 @@ pub enum Formatter {
|
||||||
Csv,
|
Csv,
|
||||||
Json,
|
Json,
|
||||||
Ids,
|
Ids,
|
||||||
|
Ical,
|
||||||
Custom(String),
|
Custom(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +43,7 @@ impl Formatter {
|
||||||
Formatter::Csv => csv::print_formatted(entries, out, ids)?,
|
Formatter::Csv => csv::print_formatted(entries, out, ids)?,
|
||||||
Formatter::Json => json::print_formatted(entries, out)?,
|
Formatter::Json => json::print_formatted(entries, out)?,
|
||||||
Formatter::Ids => ids::print_formatted(entries, out)?,
|
Formatter::Ids => ids::print_formatted(entries, out)?,
|
||||||
|
Formatter::Ical => ical::print_formatted(entries, out)?,
|
||||||
Formatter::Custom(name) => {
|
Formatter::Custom(name) => {
|
||||||
panic!("attempted custom formatter with name {} which is not implemented", name);
|
panic!("attempted custom formatter with name {} which is not implemented", name);
|
||||||
}
|
}
|
||||||
|
@ -61,6 +64,7 @@ impl FromStr for Formatter {
|
||||||
"csv" => Formatter::Csv,
|
"csv" => Formatter::Csv,
|
||||||
"json" => Formatter::Json,
|
"json" => Formatter::Json,
|
||||||
"ids" => Formatter::Ids,
|
"ids" => Formatter::Ids,
|
||||||
|
"ical" => Formatter::Ical,
|
||||||
custom_format => Formatter::Custom(custom_format.into()),
|
custom_format => Formatter::Custom(custom_format.into()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
use crate::models::Entry;
|
||||||
|
use crate::error::Result;
|
||||||
|
|
||||||
|
pub fn print_formatted<W: Write>(entries: Vec<Entry>, out: &mut W) -> Result<()> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
use chrono::{Utc, Duration};
|
||||||
|
|
||||||
|
use crate::test_utils::PrettyString;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ical_format() {
|
||||||
|
let now = Utc::now();
|
||||||
|
let an_hour_ago = now - Duration::hours(1);
|
||||||
|
let entries = vec![
|
||||||
|
Entry::new_sample(1, an_hour_ago, Some(now)),
|
||||||
|
Entry::new_sample(1, an_hour_ago, None),
|
||||||
|
];
|
||||||
|
|
||||||
|
let mut out = Vec::new();
|
||||||
|
|
||||||
|
print_formatted(entries, &mut out).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(PrettyString(&String::from_utf8_lossy(&out)), PrettyString(&format!("\
|
||||||
|
BEGIN:VCALENDAR\
|
||||||
|
CALSCALE:GREGORIAN\
|
||||||
|
METHOD:PUBLISH\
|
||||||
|
PRODID:tiempo-rs\
|
||||||
|
VERSION:2.0\
|
||||||
|
BEGIN:VEVENT\
|
||||||
|
DESCRIPTION:{note}\
|
||||||
|
DTEND:{end}\
|
||||||
|
DTSTAMP:{now}\
|
||||||
|
DTSTART:{start}\
|
||||||
|
SEQUENCE:0\
|
||||||
|
SUMMARY:{note}\
|
||||||
|
UID:{uid}@{host}\
|
||||||
|
END:VEVENT\
|
||||||
|
END:VCALENDAR\
|
||||||
|
")));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue