tavern_keeper/src/time.rs

24 lines
473 B
Rust

use std::fmt;
#[derive(Clone, Copy)]
pub struct Time{
pub time: u32,
}
impl fmt::Display for Time {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let year = self.time / 360;
let month = (self.time / 30) % 12;
let day = self.time % 30;
write!(f, "Year {}, {} of {}", year, day, month)
}
}
impl Time {
pub fn substract_years(&self, years: u32) -> Time {
Time { time: self.time - years * 360 }
}
}