minecraft_command_types/
time.rs

1use minecraft_command_types_derive::HasMacro;
2use ordered_float::NotNan;
3use std::fmt::{Display, Formatter};
4
5#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, HasMacro)]
6pub enum TimeSuffix {
7    Days,
8    Seconds,
9    Ticks,
10}
11
12impl Display for TimeSuffix {
13    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
14        match self {
15            TimeSuffix::Days => f.write_str("d"),
16            TimeSuffix::Seconds => f.write_str("s"),
17            TimeSuffix::Ticks => Ok(()),
18        }
19    }
20}
21
22#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, HasMacro)]
23pub struct Time(NotNan<f32>, Option<TimeSuffix>);
24
25impl Display for Time {
26    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27        self.0.fmt(f)?;
28
29        if let Some(suffix) = &self.1 {
30            suffix.fmt(f)?;
31        }
32
33        Ok(())
34    }
35}