All day event

This commit is contained in:
2025-09-20 13:06:21 +02:00
parent 8ae429ac54
commit a69b8a9c55
3 changed files with 30 additions and 29 deletions

View File

@ -8,6 +8,8 @@ use icalendar::{Calendar, Class, Component, Event, EventLike};
use serde::Deserialize;
use std::ops::Sub;
const TEXT_CALENDAR: &'static str = "text/calendar";
#[derive(Deserialize)]
enum Recurring {
Daily,
@ -81,8 +83,6 @@ async fn get_calendar(Query(query): Query<EventQuery>) -> impl IntoResponse {
))
}
const TEXT_CALENDAR: &'static str = "text/calendar";
async fn get_ics(Query(query): Query<EventQuery>) -> impl IntoResponse {
let start = query.start_date_time;
let end = query
@ -97,13 +97,15 @@ async fn get_ics(Query(query): Query<EventQuery>) -> impl IntoResponse {
query.avoid_weekends.unwrap_or(false),
)
.into_iter()
.for_each(|date| {
calendar.push(
Event::new()
.summary(&query.title)
.starts(date)
.class(Class::Confidential),
);
.for_each(|date_time| {
let mut event = Event::new();
if query.all_day {
event.all_day(date_time.date());
} else {
event.starts(date_time);
};
event.summary(&query.title).class(Class::Private);
calendar.push(event);
});
Response::builder()
@ -127,16 +129,15 @@ fn get_dates(
Recurring::Weeky => todo!(),
Recurring::BiWeekly => todo!(),
Recurring::Monthly => {
let new_date = baseline.checked_add_months(Months::new(1)).unwrap();
baseline = new_date;
baseline = baseline.checked_add_months(Months::new(1)).unwrap();
if let true = avoid_weekends {
match new_date.weekday() {
Weekday::Sat => new_date.sub(TimeDelta::days(1)),
Weekday::Sun => new_date.sub(TimeDelta::days(2)),
_ => new_date,
match baseline.weekday() {
Weekday::Sat => baseline.sub(TimeDelta::days(1)),
Weekday::Sun => baseline.sub(TimeDelta::days(2)),
_ => baseline,
}
} else {
new_date
baseline
}
}
Recurring::Quarterly => todo!(),