diff --git a/web/src/endpoints/availability/get_overview.rs b/web/src/endpoints/availability/get_overview.rs
index f6ff33f2..800b5ea9 100644
--- a/web/src/endpoints/availability/get_overview.rs
+++ b/web/src/endpoints/availability/get_overview.rs
@@ -1,18 +1,19 @@
-use crate::{
- filters,
- models::{find_free_date_time_slots, Assignment, Function, Vehicle},
- utils::{
- event_planning_template::generate_vehicles_assigned_and_available, ApplicationError,
- TemplateResponse,
- },
-};
use actix_web::{web, HttpResponse, Responder};
use askama::Template;
use chrono::{NaiveDate, Utc};
use serde::Deserialize;
use sqlx::PgPool;
-use crate::models::{Area, Availability, Event, Role, User};
+use crate::filters;
+use crate::models::{
+ find_free_date_time_slots, Area, Assignment, Availability, Event, Function, Role, User, Vehicle,
+};
+use crate::utils::{
+ event_planning_template::generate_vehicles_assigned_and_available,
+ ApplicationError,
+ DateTimeFormat::{DayMonthYear, DayMonthYearHourMinute, HourMinute},
+ TemplateResponse,
+};
#[derive(Deserialize)]
pub struct CalendarQuery {
diff --git a/web/src/endpoints/availability/mod.rs b/web/src/endpoints/availability/mod.rs
index 224b3e9c..155ee7d6 100644
--- a/web/src/endpoints/availability/mod.rs
+++ b/web/src/endpoints/availability/mod.rs
@@ -1,9 +1,10 @@
-use crate::filters;
use askama::Template;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use serde::Deserialize;
+use crate::filters;
use crate::models::{Availability, AvailabilityChangeset, Role, User};
+use crate::utils::DateTimeFormat::{DayMonth, DayMonthYear, DayMonthYearHourMinute};
pub mod delete;
pub mod get_new;
@@ -23,7 +24,7 @@ struct NewOrEditAvailabilityTemplate<'a> {
end: Option,
comment: Option<&'a str>,
slot_suggestions: Vec<(NaiveDateTime, NaiveDateTime)>,
- datetomorrow: NaiveDate
+ datetomorrow: NaiveDate,
}
#[derive(Deserialize)]
diff --git a/web/src/endpoints/events/mod.rs b/web/src/endpoints/events/mod.rs
index 0eb2a67c..aa39db3a 100644
--- a/web/src/endpoints/events/mod.rs
+++ b/web/src/endpoints/events/mod.rs
@@ -1,10 +1,11 @@
-use crate::filters;
use askama::Template;
use chrono::{Days, NaiveDateTime};
use chrono::{NaiveDate, NaiveTime};
use serde::Deserialize;
+use crate::filters;
use crate::models::{Location, Role, User};
+use crate::utils::DateTimeFormat::{DayMonthYear, HourMinute, YearMonthDayTHourMinute};
pub mod delete;
pub mod get_edit;
diff --git a/web/src/filters.rs b/web/src/filters.rs
index 7bb8bfbe..c573273a 100644
--- a/web/src/filters.rs
+++ b/web/src/filters.rs
@@ -3,7 +3,7 @@ use std::fmt::Display;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use maud::html;
-use crate::models::UserFunction;
+use crate::{models::UserFunction, utils::DateTimeFormat};
pub fn show_area_query(a: &Option, first: bool) -> askama::Result {
let char = if first { '?' } else { '&' };
@@ -73,38 +73,14 @@ pub fn show_tree(f: &UserFunction) -> askama::Result {
Ok(html.into_string())
}
-pub fn dt_f(v: &NaiveDateTime) -> askama::Result {
- Ok(v.format("%Y-%m-%dT%H:%M").to_string())
+pub fn fmt_date(v: &NaiveDate, format: DateTimeFormat) -> askama::Result {
+ Ok(v.format(format.into()).to_string())
}
-pub fn dt_ff(v: &NaiveDateTime) -> askama::Result {
- Ok(v.format("%d.%m.%Y %H:%M").to_string())
+pub fn fmt_datetime(v: &NaiveDateTime, format: DateTimeFormat) -> askama::Result {
+ Ok(v.format(format.into()).to_string())
}
-pub fn date_d(v: &NaiveDate) -> askama::Result {
- Ok(v.format("%d.%m.%Y").to_string())
-}
-
-pub fn date_c(v: &NaiveDate) -> askama::Result {
- Ok(v.format("%d.%m").to_string())
-}
-
-pub fn date_c_and_time(v: &NaiveDateTime) -> askama::Result {
- Ok(v.format("%d.%m. %H:%M").to_string())
-}
-
-pub fn time(v: &NaiveTime) -> askama::Result {
- Ok(v.format("%H:%M").to_string())
-}
-
-pub fn time_opt(v: &Option, default: &str) -> askama::Result {
- if let Some(t) = v {
- return time(t);
- }
-
- Ok(default.to_string())
-}
-
-pub fn dt_t(v: &NaiveDateTime) -> askama::Result {
- Ok(v.format("%R").to_string())
+pub fn fmt_time(v: &NaiveTime, format: DateTimeFormat) -> askama::Result {
+ Ok(v.format(format.into()).to_string())
}
diff --git a/web/src/utils/date_time_format.rs b/web/src/utils/date_time_format.rs
new file mode 100644
index 00000000..6b7b7c88
--- /dev/null
+++ b/web/src/utils/date_time_format.rs
@@ -0,0 +1,21 @@
+pub enum DateTimeFormat {
+ DayMonth,
+ DayMonthHourMinute,
+ DayMonthYear,
+ DayMonthYearHourMinute,
+ YearMonthDayTHourMinute,
+ HourMinute
+}
+
+impl From for &'static str {
+ fn from(value: DateTimeFormat) -> Self {
+ match value {
+ DateTimeFormat::DayMonth => "%d.%m.",
+ DateTimeFormat::DayMonthHourMinute => "%d.%m. %H:%M",
+ DateTimeFormat::DayMonthYear => "%d.%m.%Y",
+ DateTimeFormat::DayMonthYearHourMinute => "%d.%m.%Y %H:%M",
+ DateTimeFormat::YearMonthDayTHourMinute => "%Y-%m-%dT%H:%M",
+ DateTimeFormat::HourMinute => "%H:%M" // equivalent to %R,
+ }
+ }
+}
diff --git a/web/src/utils/mod.rs b/web/src/utils/mod.rs
index 9d28b76f..f848a788 100644
--- a/web/src/utils/mod.rs
+++ b/web/src/utils/mod.rs
@@ -1,5 +1,6 @@
mod application_error;
pub mod auth;
+mod date_time_format;
pub mod event_planning_template;
pub mod manage_commands;
pub mod password_change;
@@ -10,10 +11,11 @@ pub mod token_generation;
pub mod test_helper;
pub use application_error::ApplicationError;
-use chrono::{NaiveDate, Utc};
-
+pub use date_time_format::DateTimeFormat;
pub use template_response_trait::TemplateResponse;
+use chrono::{NaiveDate, Utc};
+
pub fn get_return_url_for_date(date: &NaiveDate) -> String {
let today = Utc::now().date_naive();
if date == &today {
diff --git a/web/templates/availability/new_or_edit.html b/web/templates/availability/new_or_edit.html
index c137b672..90cdea46 100644
--- a/web/templates/availability/new_or_edit.html
+++ b/web/templates/availability/new_or_edit.html
@@ -5,7 +5,8 @@
{% let is_edit = id.is_some() %}
@@ -48,12 +50,14 @@
@@ -75,9 +79,11 @@
- verfügbar von {{ date|date_c }} {{ start|time_opt("10:00")|safe }} Uhr
- bis {{ enddate.as_ref().unwrap_or(date)|date_c }}
- {{ end|time_opt("20:00")|safe }} Uhr
+ {% let start_time = start.unwrap_or(NaiveTime::from_hms_opt(10, 0, 0).unwrap()) %}
+ {% let end_time = start.unwrap_or(NaiveTime::from_hms_opt(20, 0, 0).unwrap()) %}
+ verfügbar von {{ date|fmt_date(DayMonth) }} {{ start_time|fmt_time(DayMonth) }} Uhr
+ bis {{ enddate.as_ref().unwrap_or(date)|fmt_date(DayMonth) }}
+ {{ end_time|fmt_time(DayMonth) }} Uhr
diff --git a/web/templates/events/new_or_edit.html b/web/templates/events/new_or_edit.html
index 37349b6b..40354fe3 100644
--- a/web/templates/events/new_or_edit.html
+++ b/web/templates/events/new_or_edit.html
@@ -7,7 +7,7 @@
{% if let Some(name) = name %}
Event '{{ name }}' bearbeiten
{% else %}
- Neues Event anlegen für den {{ date|date_d }}
+ Neues Event anlegen für den {{ date|fmt_date(DayMonthYear) }}
{% endif %}
@@ -74,12 +74,12 @@
diff --git a/web/templates/index.html b/web/templates/index.html
index 6278cd67..4a1e866b 100644
--- a/web/templates/index.html
+++ b/web/templates/index.html
@@ -7,7 +7,7 @@
+ href="/?date={{ date.pred() }}{{ selected_area|show_area_query(false) }}">
@@ -16,7 +16,7 @@
+ hx-get="/{{ selected_area|show_area_query(true) }}" hx-push-url="true">
{% if user.role == Role::Admin %}
@@ -36,7 +36,7 @@
+ href="/?date={{ date.succ() }}{{ selected_area|show_area_query(false) }}">
@@ -53,7 +53,7 @@
- Events am {{ date|date_d }}
+ Events am {{ date|fmt_date(DayMonthYear) }}
{% if user.role == Role::Admin || user.role == Role::AreaManager && (selected_area.is_none() ||
@@ -106,7 +106,8 @@
{% endif %}
-
Uhrzeit: {{ event.start|dt_t }} Uhr - {{ event.end|dt_ff }} Uhr
+
Uhrzeit: {{ event.start|fmt_datetime(HourMinute) }} Uhr -
+ {{ event.end|fmt_datetime(DayMonthYearHourMinute) }} Uhr
@@ -180,14 +181,14 @@
- Verfügbarkeiten am {{ date|date_d }}
+ Verfügbarkeiten am {{ date|fmt_date(DayMonthYear) }}
{% if selected_area.is_none() || selected_area.unwrap() == user.area_id %}
{% let btn_disabled = !user_can_create_availability %}