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 json;
|
||||
pub mod ids;
|
||||
pub mod ical;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
|
@ -19,6 +20,7 @@ pub enum Formatter {
|
|||
Csv,
|
||||
Json,
|
||||
Ids,
|
||||
Ical,
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
|
@ -41,6 +43,7 @@ impl Formatter {
|
|||
Formatter::Csv => csv::print_formatted(entries, out, ids)?,
|
||||
Formatter::Json => json::print_formatted(entries, out)?,
|
||||
Formatter::Ids => ids::print_formatted(entries, out)?,
|
||||
Formatter::Ical => ical::print_formatted(entries, out)?,
|
||||
Formatter::Custom(name) => {
|
||||
panic!("attempted custom formatter with name {} which is not implemented", name);
|
||||
}
|
||||
|
@ -61,6 +64,7 @@ impl FromStr for Formatter {
|
|||
"csv" => Formatter::Csv,
|
||||
"json" => Formatter::Json,
|
||||
"ids" => Formatter::Ids,
|
||||
"ical" => Formatter::Ical,
|
||||
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