From 8fb69df54873efd6e355329b222957c99acfa433 Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 19 Nov 2021 19:49:52 +0100 Subject: [PATCH] Create own Time This allows me to use "24:00" as time --- src/commands.rs | 56 +++++++++++++++++++++++++++++-------------------- src/parse.rs | 12 +++++------ 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index b331f02..08ed3de 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,4 +1,23 @@ -use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; +use chrono::{NaiveDate, NaiveDateTime}; + +#[derive(Debug)] +pub struct Time { + hour: u8, + min: u8, +} + +impl Time { + pub fn new(hour: u32, min: u32) -> Option { + if hour < 24 && min < 60 || hour == 24 && min == 0 { + Some(Self { + hour: hour as u8, + min: min as u8, + }) + } else { + None + } + } +} #[derive(Debug)] pub enum Weekday { @@ -36,34 +55,24 @@ pub enum DeltaStep { #[derive(Debug)] pub struct Delta(pub Vec); -#[derive(Debug)] -pub struct DateEndSpec { - pub end: Option, - pub delta: Option, - pub end_time: Option, -} - #[derive(Debug)] pub struct DateSpec { pub start: NaiveDate, - pub delta: Option, - pub start_time: Option, - pub end: Option, + pub start_delta: Option, + pub start_time: Option