mirror of
https://github.com/jhbruhn/ics-adapter.git
synced 2025-03-15 03:25:49 +00:00
Implement rrule parsing
This commit is contained in:
parent
a89a0dbd3a
commit
e555eb611e
3 changed files with 51 additions and 1 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -2,6 +2,15 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android-tzdata"
|
name = "android-tzdata"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
@ -480,6 +489,7 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"icalendar",
|
"icalendar",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"rrule",
|
||||||
"serde",
|
"serde",
|
||||||
"tokio",
|
"tokio",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
|
@ -937,6 +947,8 @@ version = "1.8.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
|
checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
"regex-syntax",
|
"regex-syntax",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -983,6 +995,20 @@ dependencies = [
|
||||||
"winreg",
|
"winreg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rrule"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "615777991e415d96aa97f6e45e809111911497c029e5d0df7f6d751d218d28e8"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"chrono-tz",
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "0.37.20"
|
version = "0.37.20"
|
||||||
|
|
|
@ -14,3 +14,4 @@ icalendar = { version = "0.15", features = ["chrono-tz"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
urlencoding = "2"
|
urlencoding = "2"
|
||||||
chrono = "0"
|
chrono = "0"
|
||||||
|
rrule = "0"
|
||||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -80,10 +80,33 @@ async fn convert(urls: &[&str], days: Option<&String>) -> Result<CustomCalendar>
|
||||||
None => start + chrono::Duration::days(1),
|
None => start + chrono::Duration::days(1),
|
||||||
};
|
};
|
||||||
|
|
||||||
if start < filter_start || start > filter_end {
|
let length = end - start;
|
||||||
|
|
||||||
|
let start_dates = if let Some(rrule) = event.properties().get("RRULE") {
|
||||||
|
//let vector = Vec::new();
|
||||||
|
let rrule_str = rrule.value();
|
||||||
|
let string = format!("DTSTART:{}\n{}", event.properties().get("DTSTART").unwrap().value(), rrule_str);
|
||||||
|
let rrule: rrule::RRuleSet = string.parse()?;
|
||||||
|
let date_set = rrule.all(100).dates;
|
||||||
|
date_set.iter().map(|x| x.with_timezone(&chrono::Utc)).collect()
|
||||||
|
} else {
|
||||||
|
vec!(start)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut found = false;
|
||||||
|
for start_date in start_dates {
|
||||||
|
if start_date >= filter_start && start_date <= filter_end {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let end = start + length;
|
||||||
|
|
||||||
entries.push(CustomCalendarEntry {
|
entries.push(CustomCalendarEntry {
|
||||||
title: event.get_summary().unwrap_or("").to_string(),
|
title: event.get_summary().unwrap_or("").to_string(),
|
||||||
description: event.get_description().unwrap_or("").to_string(),
|
description: event.get_description().unwrap_or("").to_string(),
|
||||||
|
|
Loading…
Reference in a new issue