Introduce more styles and dates sessions
This commit is contained in:
parent
da42de5c92
commit
9439593409
97
src/lib.rs
97
src/lib.rs
@ -1,9 +1,102 @@
|
|||||||
use crate::session_date_calculator::Day;
|
use crate::session_date_calculator::{Day, NthWeekday};
|
||||||
use chrono::Weekday;
|
use chrono::{NaiveDate, Weekday};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub mod session_date_calculator;
|
pub mod session_date_calculator;
|
||||||
pub mod webpage;
|
pub mod webpage;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct DatedSession {
|
||||||
|
pub day: Day,
|
||||||
|
pub session: Session,
|
||||||
|
pub applying_exception: Option<Exception>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Noted for DatedSession {
|
||||||
|
fn note(&self) -> Option<&String> {
|
||||||
|
match &self.applying_exception {
|
||||||
|
Some(e) => e.note(),
|
||||||
|
None => self.session.note(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub enum Session {
|
||||||
|
Regular {
|
||||||
|
rule: NthWeekday,
|
||||||
|
note: Option<String>,
|
||||||
|
except: HashMap<NaiveDate, Exception>,
|
||||||
|
},
|
||||||
|
Extra {
|
||||||
|
date: NaiveDate,
|
||||||
|
note: Option<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Session {
|
||||||
|
pub fn into_dated(self, day: Day) -> Result<DatedSession, Self> {
|
||||||
|
if !self.is_applicable_to(&day) {
|
||||||
|
return Err(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
let dated_session = DatedSession {
|
||||||
|
applying_exception: match self {
|
||||||
|
Session::Regular { ref except, .. } => except.get(&day.date).cloned(),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
session: self,
|
||||||
|
day,
|
||||||
|
};
|
||||||
|
Ok(dated_session)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_applicable_to(&self, day: &Day) -> bool {
|
||||||
|
match *self {
|
||||||
|
Session::Regular { rule, .. } => rule.matches(day),
|
||||||
|
Session::Extra { date, .. } => day.date == date,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Noted for Session {
|
||||||
|
fn note(&self) -> Option<&String> {
|
||||||
|
match self {
|
||||||
|
Session::Regular { note, .. } => note,
|
||||||
|
Session::Extra { note, .. } => note,
|
||||||
|
}
|
||||||
|
.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||||
|
pub enum Exception {
|
||||||
|
Cancel {
|
||||||
|
note: Option<String>,
|
||||||
|
},
|
||||||
|
Alter {
|
||||||
|
#[serde(default)]
|
||||||
|
date: Option<NaiveDate>,
|
||||||
|
#[serde(default)]
|
||||||
|
note: Option<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Noted for Exception {
|
||||||
|
fn note(&self) -> Option<&String> {
|
||||||
|
match self {
|
||||||
|
Exception::Cancel { note, .. } => note,
|
||||||
|
Exception::Alter { note, .. } => note,
|
||||||
|
}
|
||||||
|
.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Noted {
|
||||||
|
fn note(&self) -> Option<&String>;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn localize_day(day: &Day) -> String {
|
pub fn localize_day(day: &Day) -> String {
|
||||||
format!(
|
format!(
|
||||||
"{}, {}",
|
"{}, {}",
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use std::fmt::{Display, Formatter};
|
|||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||||
pub struct NthWeekday {
|
pub struct NthWeekday {
|
||||||
pub n: u8,
|
pub n: u8,
|
||||||
pub weekday: Weekday,
|
pub weekday: Weekday,
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
--white: white;
|
--white: white;
|
||||||
--black: black;
|
--black: black;
|
||||||
--red: red;
|
--red: red;
|
||||||
--yellow: #f0f00f;
|
--yellow: #bbbb11;
|
||||||
--green: #1fd51f;
|
--green: #1fd51f;
|
||||||
}
|
}
|
||||||
ul {
|
ul {
|
||||||
@ -70,6 +70,9 @@ html, body {
|
|||||||
.highlight-background {
|
.highlight-background {
|
||||||
background-color: var(--green);
|
background-color: var(--green);
|
||||||
}
|
}
|
||||||
.red-text {
|
.cancel-background {
|
||||||
color: var(--red);
|
background-color: var(--red);
|
||||||
|
}
|
||||||
|
.change-background {
|
||||||
|
background-color: var(--yellow);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user