aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-08-23 17:06:24 +0200
committerHarald Eilertsen <haraldei@anduin.net>2020-08-23 17:06:24 +0200
commitd3a6a99e9c1751ec08bed526d4ce7237425cdf73 (patch)
tree1a045f2d0059610a5bc60d200f6becf309a211a8 /src/controllers
parent0a2d6fc06fc1988f860ab81fe53d1e6dae470407 (diff)
downloadramaskrik-social-d3a6a99e9c1751ec08bed526d4ce7237425cdf73.tar.gz
ramaskrik-social-d3a6a99e9c1751ec08bed526d4ce7237425cdf73.tar.bz2
ramaskrik-social-d3a6a99e9c1751ec08bed526d4ce7237425cdf73.zip
Change start/end times to complete timestamps.
The way we had this until now with a date and separate start and end times does not really work. There are cases when a screening starts on one day, but ends on the next. By keeping a complete timestamp for both the start and end times, we don't fall into this problem.
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/screening.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/controllers/screening.rs b/src/controllers/screening.rs
index 9e78130..aca8e32 100644
--- a/src/controllers/screening.rs
+++ b/src/controllers/screening.rs
@@ -68,18 +68,21 @@ 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,
}
#[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 date = chrono::NaiveDate::parse_from_str(dbg!(&screening.date), "%Y-%m-%d")?;
- let start_time = chrono::NaiveTime::parse_from_str(dbg!(&screening.start_time), "%H:%M")?;
- let end_time = chrono::NaiveTime::parse_from_str(dbg!(&screening.end_time), "%H:%M")?;
+ let start_time = chrono::DateTime::parse_from_rfc3339(dbg!(&screening.start_time))?;
+ let end_time = chrono::DateTime::parse_from_rfc3339(dbg!(&screening.end_time))?;
+
+ db.create_screening(
+ dbg!(screening.room_id),
+ dbg!(screening.film_id),
+ start_time.with_timezone(&chrono::Utc),
+ end_time.with_timezone(&chrono::Utc))?;
- db.create_screening(dbg!(screening.room_id), dbg!(screening.film_id), date, start_time, end_time)?;
Ok(Redirect::to("/screenings"))
}