1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use super::TimePoint;
use crate::bytes::{NumBytes, Read, Write};
use core::ops::Add;
#[derive(
Read,
Write,
NumBytes,
PartialEq,
Eq,
PartialOrd,
Ord,
Debug,
Clone,
Copy,
Hash,
Default,
)]
#[eosio(crate_path = "crate::bytes")]
pub struct TimePointSec(u32);
impl TimePointSec {
#[inline]
#[must_use]
pub const fn from_secs(secs: u32) -> Self {
Self(secs)
}
#[inline]
#[must_use]
pub const fn as_secs(self) -> u32 {
self.0
}
}
impl From<u32> for TimePointSec {
#[inline]
#[must_use]
fn from(i: u32) -> Self {
Self(i)
}
}
impl From<TimePointSec> for u32 {
#[inline]
#[must_use]
fn from(t: TimePointSec) -> Self {
t.0
}
}
impl From<TimePoint> for TimePointSec {
#[inline]
#[must_use]
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
fn from(t: TimePoint) -> Self {
Self((t.as_micros() as u32) / 1_000_000_u32)
}
}
impl Add<u32> for TimePointSec {
type Output = Self;
#[must_use]
fn add(self, rhs: u32) -> Self::Output {
Self(self.0 + rhs)
}
}
impl Add<TimePointSec> for u32 {
type Output = TimePointSec;
#[must_use]
fn add(self, rhs: TimePointSec) -> Self::Output {
TimePointSec(rhs.0 + self)
}
}