aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-08-23 20:47:29 +0200
committerHarald Eilertsen <haraldei@anduin.net>2020-08-23 20:47:29 +0200
commit97198afd29a8d41e5ab9f9edd5f9f71b38c9d355 (patch)
tree64e83da633dafbc0792c9eabf0ca30ac45cb6677 /src
parentd3a6a99e9c1751ec08bed526d4ce7237425cdf73 (diff)
downloadramaskrik-social-97198afd29a8d41e5ab9f9edd5f9f71b38c9d355.tar.gz
ramaskrik-social-97198afd29a8d41e5ab9f9edd5f9f71b38c9d355.tar.bz2
ramaskrik-social-97198afd29a8d41e5ab9f9edd5f9f71b38c9d355.zip
Store timestamps in UTC.
For now we just hardcode that the local timezone of the site is UTC+2. Good enough for now, but something that should be configurable. Also split the date and time entries in the form again, the date refers to the start date. If the end time is before the start time, we assume it's the day after. Again, good enough for now.
Diffstat (limited to 'src')
-rw-r--r--src/controllers/screening.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/controllers/screening.rs b/src/controllers/screening.rs
index aca8e32..40eefd3 100644
--- a/src/controllers/screening.rs
+++ b/src/controllers/screening.rs
@@ -68,20 +68,30 @@ pub fn new_screening(db: db::Connection) -> Result<Template, Box<dyn Error>> {
pub struct NewScreeningForm {
film_id: i32,
room_id: i32,
+ date: String,
start_time: String,
end_time: String,
}
+fn parse_datetime(date: &str, time: &str) -> Result<chrono::DateTime<chrono::Utc>, Box<dyn Error>> {
+ let dts = format!("{}T{}:00+02:00", &date, &time);
+ Ok(chrono::DateTime::parse_from_rfc3339(&dts)?.with_timezone(&chrono::Utc))
+}
+
#[post("/", format = "application/x-www-form-urlencoded", data = "<screening>")]
pub fn create_screening(db: db::Connection, screening: Form<NewScreeningForm>) -> Result<Redirect, Box<dyn Error>> {
- let start_time = chrono::DateTime::parse_from_rfc3339(dbg!(&screening.start_time))?;
- let end_time = chrono::DateTime::parse_from_rfc3339(dbg!(&screening.end_time))?;
+ let start_time = parse_datetime(&screening.date, &screening.start_time)?;
+ let mut end_time = parse_datetime(&screening.date, &screening.end_time)?;
+
+ if end_time < start_time {
+ end_time = end_time + chrono::Duration::days(1);
+ }
db.create_screening(
- dbg!(screening.room_id),
- dbg!(screening.film_id),
- start_time.with_timezone(&chrono::Utc),
- end_time.with_timezone(&chrono::Utc))?;
+ screening.room_id,
+ screening.film_id,
+ start_time,
+ end_time)?;
Ok(Redirect::to("/screenings"))
}