Julio Biason
4 years ago
6 changed files with 253 additions and 107 deletions
@ -0,0 +1,53 @@ |
|||||||
|
/* |
||||||
|
TU - Time's Up! |
||||||
|
Copyright (C) 2020 Julio Biason |
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU Affero General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU Affero General Public License for more details. |
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License |
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
use chrono::prelude::*; |
||||||
|
use chrono::DateTime; |
||||||
|
use serde_derive::Deserialize; |
||||||
|
use serde_derive::Serialize; |
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)] |
||||||
|
pub struct Date { |
||||||
|
year: i32, |
||||||
|
month: u32, |
||||||
|
day: u32, |
||||||
|
} |
||||||
|
|
||||||
|
impl From<&DateTime<Local>> for Date { |
||||||
|
fn from(origin: &DateTime<Local>) -> Date { |
||||||
|
Date { |
||||||
|
year: origin.year(), |
||||||
|
month: origin.month(), |
||||||
|
day: origin.day(), |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl Date { |
||||||
|
pub fn year(&self) -> i32 { |
||||||
|
self.year |
||||||
|
} |
||||||
|
|
||||||
|
pub fn month(&self) -> u32 { |
||||||
|
self.month |
||||||
|
} |
||||||
|
|
||||||
|
pub fn day(&self) -> u32 { |
||||||
|
self.day |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,61 @@ |
|||||||
|
/* |
||||||
|
TU - Time's Up! |
||||||
|
Copyright (C) 2020 Julio Biason |
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU Affero General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU Affero General Public License for more details. |
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License |
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
use chrono::prelude::*; |
||||||
|
use chrono::DateTime; |
||||||
|
use serde_derive::Deserialize; |
||||||
|
use serde_derive::Serialize; |
||||||
|
|
||||||
|
use crate::eventlist::event::date; |
||||||
|
use crate::eventlist::event::time; |
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)] |
||||||
|
#[serde(tag = "due", content = "datetime")] |
||||||
|
pub enum EventType { |
||||||
|
AllDay(date::Date), |
||||||
|
AtTime(date::Date, time::Time), |
||||||
|
} |
||||||
|
|
||||||
|
impl From<&EventType> for DateTime<Local> { |
||||||
|
fn from(origin: &EventType) -> Self { |
||||||
|
match origin { |
||||||
|
EventType::AllDay(d) => Local.ymd(d.year(), d.month(), d.day()).and_hms(23, 59, 59), |
||||||
|
EventType::AtTime(d, t) => { |
||||||
|
Local |
||||||
|
.ymd(d.year(), d.month(), d.day()) |
||||||
|
.and_hms(t.hour(), t.minute(), 59) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl From<&EventType> for String { |
||||||
|
fn from(origin: &EventType) -> String { |
||||||
|
match origin { |
||||||
|
EventType::AllDay(d) => format!("{}{}{}0000", d.year(), d.month(), d.day()), |
||||||
|
EventType::AtTime(d, t) => format!( |
||||||
|
"{}{}{}{}{}", |
||||||
|
d.year(), |
||||||
|
d.month(), |
||||||
|
d.day(), |
||||||
|
t.hour(), |
||||||
|
t.minute() |
||||||
|
), |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
/* |
||||||
|
TU - Time's Up! |
||||||
|
Copyright (C) 2020 Julio Biason |
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU Affero General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU Affero General Public License for more details. |
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License |
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
use chrono::prelude::*; |
||||||
|
use chrono::DateTime; |
||||||
|
use serde_derive::Deserialize; |
||||||
|
use serde_derive::Serialize; |
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)] |
||||||
|
pub struct Time { |
||||||
|
hour: u32, |
||||||
|
min: u32, |
||||||
|
} |
||||||
|
|
||||||
|
impl From<&DateTime<Local>> for Time { |
||||||
|
fn from(origin: &DateTime<Local>) -> Time { |
||||||
|
Time { |
||||||
|
hour: origin.hour(), |
||||||
|
min: origin.minute(), |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl Time { |
||||||
|
pub fn hour(&self) -> u32 { |
||||||
|
self.hour |
||||||
|
} |
||||||
|
|
||||||
|
pub fn minute(&self) -> u32 { |
||||||
|
self.min |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue