gix_date/time/
mod.rs

1use crate::Time;
2
3/// Access
4impl Time {
5    /// Return true if this time has been initialized to anything non-default, i.e. 0.
6    pub fn is_set(&self) -> bool {
7        *self != Self::default()
8    }
9}
10
11/// Indicates if a number is positive or negative for use in [`Time`].
12#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14#[allow(missing_docs)]
15pub enum Sign {
16    Plus,
17    Minus,
18}
19
20/// Various ways to describe a time format.
21#[derive(Debug, Clone, Copy)]
22pub enum Format {
23    /// A custom format limited to what's in the [`format`](mod@format) submodule.
24    Custom(CustomFormat),
25    /// The seconds since 1970, also known as unix epoch, like `1660874655`.
26    Unix,
27    /// The seconds since 1970, followed by the offset, like `1660874655 +0800`
28    Raw,
29}
30
31/// A custom format for printing and parsing time.
32#[derive(Clone, Copy, Debug)]
33pub struct CustomFormat(pub(crate) &'static str);
34
35impl CustomFormat {
36    /// Create a new custom `format` suitable for use with the [`jiff`] crate.
37    pub const fn new(format: &'static str) -> Self {
38        Self(format)
39    }
40}
41
42impl From<CustomFormat> for Format {
43    fn from(custom_format: CustomFormat) -> Format {
44        Format::Custom(custom_format)
45    }
46}
47
48///
49pub mod format;
50mod init;
51mod write;
52
53mod sign {
54    use crate::time::Sign;
55
56    impl From<i32> for Sign {
57        fn from(v: i32) -> Self {
58            if v < 0 {
59                Sign::Minus
60            } else {
61                Sign::Plus
62            }
63        }
64    }
65}
66
67mod impls {
68    use crate::{time::Sign, Time};
69
70    impl Default for Time {
71        fn default() -> Self {
72            Time {
73                seconds: 0,
74                offset: 0,
75                sign: Sign::Plus,
76            }
77        }
78    }
79}