aboutsummaryrefslogtreecommitdiff
path: root/apps/cassiopeia/src/lib.rs
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-12-19 15:15:20 +0000
committerMx Kookie <kookie@spacekookie.de>2020-12-21 05:19:49 +0100
commit69eaad1c9f934bccaf7e28529a6b1657345f0184 (patch)
tree4e7517a16f7303f5f6efbd02e4aae85bdc5aec29 /apps/cassiopeia/src/lib.rs
parentb9c988f42504c2e4cfa0715ac8f2d2a0db591cad (diff)
cassiopeia: changing internal data representation to timeline module
What this allows us to do is much better relationship tracking between sessions and invoices. The CASS file already has all the structure we need, and it would be silly to replicate it via complicated time association algorithms. This approach uses the linear nature of the data file to track the position relative to other entries. The timeline module is then responsible for making changes to the internal representation (in case it is being used as a library for multi-query commands), and emitting a `Delta` type that can be used to easily patch the IR in question, because the mapping between the timeline and IR representations is linear.
Diffstat (limited to 'apps/cassiopeia/src/lib.rs')
-rw-r--r--apps/cassiopeia/src/lib.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/apps/cassiopeia/src/lib.rs b/apps/cassiopeia/src/lib.rs
index e391c695237e..895110fe218d 100644
--- a/apps/cassiopeia/src/lib.rs
+++ b/apps/cassiopeia/src/lib.rs
@@ -10,9 +10,11 @@
mod data;
mod date;
+mod error;
mod format;
pub mod meta;
mod time;
+mod timeline;
pub use date::Date;
pub use time::Time;
@@ -46,17 +48,17 @@ impl Cassiopeia {
/// Start a new work session (with optional 15 minute rounding)
pub fn start(&mut self, round: bool) -> Option<()> {
- let s = self.tf.start(round)?;
+ let delta = self.tf.timeline.start(Time::rounded(round)).ok()?;
clean_ir(&mut self.ir);
- append_ir(&mut self.ir, s.make_ir());
+ append_ir(&mut self.ir, delta.make_ir());
format::write_file(self.path.as_str(), &mut self.ir)
}
/// Stop the existing work session (with optional 15 minute rounding)
pub fn stop(&mut self, round: bool) -> Option<()> {
- let s = self.tf.stop(round)?;
+ let delta = self.tf.timeline.stop(Time::rounded(round)).ok()?;
clean_ir(&mut self.ir);
- append_ir(&mut self.ir, s.make_ir());
+ append_ir(&mut self.ir, delta.make_ir());
format::write_file(self.path.as_str(), &mut self.ir)
}
@@ -70,6 +72,11 @@ impl Cassiopeia {
clean_ir(&mut self.ir);
format::write_file(self.path.as_str(), &mut self.ir)
}
+
+ /// Collect statistics on previous work sessions
+ pub fn stat(&self) -> Option<String> {
+ None
+ }
}
/// An invoice generator builder
@@ -142,9 +149,9 @@ impl<'cass> Invoicer<'cass> {
return None;
}
- let inv = self.tf.tf.invoice()?;
+ let delta = self.tf.tf.timeline.invoice(Date::today()).ok()?;
clean_ir(&mut self.tf.ir);
- append_ir(&mut self.tf.ir, inv.make_ir());
+ append_ir(&mut self.tf.ir, delta.make_ir());
format::write_file(self.tf.path.as_str(), &mut self.tf.ir)
}
}