use chrono::NaiveDateTime;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Attendance {
pub uid: u32,
pub user_id: String,
pub timestamp: NaiveDateTime,
pub status: u8,
pub punch: u8,
}
impl Attendance {
pub fn new(
user_id: impl Into<String>,
timestamp: NaiveDateTime,
status: u8,
punch: u8,
uid: u32,
) -> Self {
Attendance {
uid,
user_id: user_id.into(),
timestamp,
status,
punch,
}
}
pub fn punch_label(&self) -> String {
match self.punch {
0 => "check-in".into(),
1 => "check-out".into(),
2 => "break-out".into(),
3 => "break-in".into(),
4 => "overtime-in".into(),
5 => "overtime-out".into(),
other => format!("punch {other}"),
}
}
}
impl fmt::Display for Attendance {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"<Attendance>: {} : {} ({}, {})",
self.user_id, self.timestamp, self.status, self.punch
)
}
}