refactor: rewrite in rust
All checks were successful
Continuous Integration / Lint, Check & Test (push) Successful in 2m32s
Continuous Integration / Build Package (push) Successful in 3m0s

This commit is contained in:
Konstantin Fickel 2026-03-29 18:19:15 +02:00
parent 20a3e8b437
commit 4116a7042d
Signed by: kfickel
GPG key ID: A793722F9933C1A5
72 changed files with 5683 additions and 3686 deletions

77
src/models/timecard.rs Normal file
View file

@ -0,0 +1,77 @@
use chrono::NaiveDate;
use chrono::NaiveTime;
use serde::{Deserialize, Serialize};
/// Type of special day that affects timesheet calculations.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SpecialDayType {
#[serde(rename = "VACATION")]
Vacation,
#[serde(rename = "UNDERTIME")]
Undertime,
#[serde(rename = "HOLIDAY")]
Holiday,
#[serde(rename = "WEEKEND")]
Weekend,
}
impl std::fmt::Display for SpecialDayType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SpecialDayType::Vacation => write!(f, "VACATION"),
SpecialDayType::Undertime => write!(f, "UNDERTIME"),
SpecialDayType::Holiday => write!(f, "HOLIDAY"),
SpecialDayType::Weekend => write!(f, "WEEKEND"),
}
}
}
/// A Timecard represents a single work period with start and end times.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Timecard {
pub from_time: NaiveTime,
pub to_time: NaiveTime,
}
impl Timecard {
pub fn new(from_time: NaiveTime, to_time: NaiveTime) -> Self {
Self { from_time, to_time }
}
}
/// A Timesheet aggregates all time tracking information for a single day.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Timesheet {
pub date: NaiveDate,
#[serde(default)]
pub is_sick_leave: bool,
#[serde(default)]
pub special_day_type: Option<SpecialDayType>,
pub timecards: Vec<Timecard>,
}
impl Timesheet {
pub fn new(date: NaiveDate) -> Self {
Self {
date,
is_sick_leave: false,
special_day_type: None,
timecards: Vec::new(),
}
}
pub fn with_sick_leave(mut self, is_sick_leave: bool) -> Self {
self.is_sick_leave = is_sick_leave;
self
}
pub fn with_special_day_type(mut self, special_day_type: SpecialDayType) -> Self {
self.special_day_type = Some(special_day_type);
self
}
pub fn with_timecards(mut self, timecards: Vec<Timecard>) -> Self {
self.timecards = timecards;
self
}
}