xwrust/
xwtm.rs

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! XWOS RUST:系统时间
//! ========
//!
//! XWOS的系统时间库。
//!

use crate::types::*;

extern "C" {
    fn xwrustffi_xwtm_now() -> XwTm;
    fn xwrustffi_xwtm_ft(time: XwTm) -> XwTm;
    fn xwrustffi_xwtm_nowts() -> XwTm;
    fn xwrustffi_xwtm_fts(time: XwTm) -> XwTm;
    fn xwrustffi_xwtm_nowtc() -> u64;
}

/// 1微秒
pub const MICROSECOND: XwTm = 1000;
/// 1毫秒
pub const MILLISECOND: XwTm = 1000000;
/// 1秒
pub const SECOND: XwTm = 1000000000;
/// 1分
pub const MINUTE: XwTm = 60000000000;
/// 1小时
pub const HOUR: XwTm = 3600000000000;
/// 1天
pub const DAY: XwTm = 86400000000000;


/// 获取当前CPU的 **系统时间** 点
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let now = xwtm::now();
/// ```
pub fn now() -> XwTm {
    unsafe { xwrustffi_xwtm_now() }
}


/// 获取当前CPU的未来 **系统时间** 点
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let ftp = xwtm::ft(xwtm::s(1));
/// ```
pub fn ft(time: XwTm) -> XwTm {
    unsafe { xwrustffi_xwtm_ft(time) }
}


/// 获取当前CPU的 **系统时间戳**
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let ts = xwtm::nowts();
/// ```
pub fn nowts() -> XwTm {
    unsafe { xwrustffi_xwtm_nowts() }
}


/// 获取当前CPU的未来 **系统时间戳**
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let ftp = xwtm::fts(xwtm::s(1));
/// ```
pub fn fts(time: XwTm) -> XwTm {
    unsafe { xwrustffi_xwtm_fts(time) }
}


/// 获取当前CPU的系统滴答计数
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let cnt = xwtm::nowtc();
/// ```
pub fn nowtc() -> u64 {
    unsafe { xwrustffi_xwtm_nowtc() }
}


/// 返回以微秒为单位的系统时间
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let tp = xwtm::us(8); // 8微妙
/// ```
pub const fn us(us: XwTm) -> XwTm {
    us * MICROSECOND
}


/// 返回以毫秒为单位的系统时间
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let tp = xwtm::ms(8); // 8毫妙
/// ```
pub const fn ms(ms: XwTm) -> XwTm {
    ms * MILLISECOND
}


/// 返回以秒为单位的系统时间
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let tp = xwtm::s(8); // 8妙
/// ```
pub const fn s(s: XwTm) -> XwTm {
    s * SECOND
}


/// 返回以分为单位的系统时间
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let tp = xwtm::m(8); // 8分
/// ```
pub const fn m(m: XwTm) -> XwTm {
    m * MINUTE
}


/// 返回以小时为单位的系统时间
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let tp = xwtm::h(8); // 8小时
/// ```
pub const fn h(h: XwTm) -> XwTm {
    h * HOUR
}


/// 返回以天为单位的系统时间
///
/// # 示例
///
/// ```rust
/// use use xwrust::xwtm;
///
/// let tp = xwtm::d(8); // 8天
/// ```
pub const fn d(d: XwTm) -> XwTm {
    d * DAY
}