]> git.proxmox.com Git - rustc.git/blob - vendor/gix-date/src/time/mod.rs
612a3cdef82db527bc7fca2a23e57f0c6b0957f8
[rustc.git] / vendor / gix-date / src / time / mod.rs
1 use crate::Time;
2
3 /// Access
4 impl 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 = "serde", derive(serde::Serialize, serde::Deserialize))]
19 #[allow(missing_docs)]
20 pub enum Sign {
21 Plus,
22 Minus,
23 }
24
25 /// Various ways to describe a time format.
26 #[derive(Debug, Clone, Copy)]
27 pub 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 ///
37 pub mod format;
38 mod init;
39 mod write;
40
41 mod 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
55 mod 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 }