1#[cfg(feature = "interim")]
2use std::str::FromStr;
3use chrono::NaiveDateTime;
4#[cfg(feature = "interim")]
5use chrono::Local;
6#[cfg(feature = "interim")]
7use interim::{parse_date_string, DateError, Dialect};
8use sanakirja::Storable;
9use sanakirja::btree::{Db, UDb};
10
11#[derive(Debug, Default, Ord, PartialOrd, Eq, PartialEq, Clone, Copy)]
12pub struct Session {
13 pub start: NaiveDateTime,
14 pub end: NaiveDateTime,
15}
16
17impl Storable for Session {
18 type PageReferences = core::iter::Empty<u64>;
19 fn page_references(&self) -> Self::PageReferences {
20 core::iter::empty()
21 }
22
23 fn compare<T>(&self, _: &T, b: &Self) -> core::cmp::Ordering {
24 self.cmp(b)
25 }
26}
27
28#[cfg(feature = "interim")]
29impl FromStr for Session {
30 type Err = DateError;
31
32 fn from_str(s: &str) -> Result<Self, Self::Err> {
33 match s.split_once(" to ") {
34 Some((s, e)) => Ok(Session {
35 start: parse_date_string(s, Local::now(), Dialect::Uk)?.naive_local(),
36 end: parse_date_string(e, Local::now(), Dialect::Uk)?.naive_local(),
37 }),
38 None => Err(DateError::MissingDate),
39 }
40 }
41}
42
43pub(crate) type LinksDb = Db<u64, u64>;
44pub(crate) type RLinksDb = Db<u64, RTriple>;
45pub(crate) type NamesDb = UDb<u64, [u8]>;
46pub(crate) type DueDatesDb = Db<u64, DueDate>;
47pub(crate) type SessionsDb = Db<u64, Session>;
48pub(crate) type RSessionsDb = Db<Session, u64>;
49
50#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
51pub(crate) struct RTriple {
52 pub pid: u64,
53 pub next: u64,
54 pub prev: u64,
55}
56
57impl Storable for RTriple {
58 type PageReferences = core::iter::Empty<u64>;
59 fn page_references(&self) -> Self::PageReferences {
60 core::iter::empty()
61 }
62
63 fn compare<T>(&self, _: &T, b: &Self) -> core::cmp::Ordering {
64 self.cmp(b)
65 }
66}
67
68#[derive(Debug, Default, Ord, PartialOrd, Eq, PartialEq)]
69pub(crate) struct DueDate(pub NaiveDateTime);
70
71impl Storable for DueDate {
72 type PageReferences = core::iter::Empty<u64>;
73 fn page_references(&self) -> Self::PageReferences {
74 core::iter::empty()
75 }
76
77 fn compare<T>(&self, _: &T, b: &Self) -> core::cmp::Ordering {
78 self.cmp(b)
79 }
80}