git_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    /// Return the passed seconds since epoch since this signature was made.
11    pub fn seconds(&self) -> u32 {
12        self.seconds_since_unix_epoch
13    }
14}
15
16/// Indicates if a number is positive or negative for use in [`Time`].
17#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
18#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
19#[allow(missing_docs)]
20pub enum Sign {
21    Plus,
22    Minus,
23}
24
25/// Various ways to describe a time format.
26#[derive(Debug, Clone, Copy)]
27pub enum Format<'a> {
28    /// A custom format typically defined with the [`format_description`][time::format_description] macro.
29    Custom(&'a [time::format_description::FormatItem<'a>]),
30    /// The seconds since 1970, also known as unix epoch, like `1660874655`.
31    Unix,
32    /// The seconds since 1970, followed by the offset, like `1660874655 +0800`
33    Raw,
34}
35
36///
37pub mod format;
38mod init;
39mod write;
40
41mod sign {
42    use crate::time::Sign;
43
44    impl From<i32> for Sign {
45        fn from(v: i32) -> Self {
46            if v < 0 {
47                Sign::Minus
48            } else {
49                Sign::Plus
50            }
51        }
52    }
53}
54
55mod impls {
56    use crate::{time::Sign, Time};
57
58    impl Default for Time {
59        fn default() -> Self {
60            Time {
61                seconds_since_unix_epoch: 0,
62                offset_in_seconds: 0,
63                sign: Sign::Plus,
64            }
65        }
66    }
67}