Skip to main content

nil_server_types/
time.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use derive_more::{From, Into};
5use serde::{Deserialize, Serialize};
6use std::time::Duration;
7
8#[derive(Copy, Debug, From, Into, Deserialize, Serialize)]
9#[derive_const(Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
10#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
11#[cfg_attr(feature = "typescript", ts(as = "u32"))]
12pub struct Minutes(u64);
13
14impl Minutes {
15  pub const fn new(mins: u64) -> Self {
16    Self(mins)
17  }
18}
19
20impl const From<Duration> for Minutes {
21  fn from(duration: Duration) -> Self {
22    Self(duration.as_secs() / 60)
23  }
24}
25
26impl const From<Minutes> for Duration {
27  fn from(value: Minutes) -> Self {
28    Duration::from_mins(value.0)
29  }
30}