File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ pub mod std_vendor;
4646pub mod str;
4747pub mod sync;
4848pub mod task;
49+ pub mod time;
4950pub mod types;
5051
5152#[ doc( hidden) ]
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: GPL-2.0
2+
3+ //! Time representation in the kernel.
4+ //!
5+ //! C headers: [`include/linux/time64.h`](../../include/linux/time64.h)
6+
7+ use crate :: { bindings, error:: Result } ;
8+
9+ /// A [`Time`] instance at the Unix epoch.
10+ pub const UNIX_EPOCH : Time = Time {
11+ t : bindings:: timespec64 {
12+ tv_sec : 0 ,
13+ tv_nsec : 0 ,
14+ } ,
15+ } ;
16+
17+ /// A timestamp.
18+ #[ derive( Copy , Clone ) ]
19+ pub struct Time {
20+ t : bindings:: timespec64 ,
21+ }
22+
23+ impl Time {
24+ /// Creates a new timestamp.
25+ ///
26+ /// `sec` is the number of seconds since the Unix epoch. `nsec` is the number of nanoseconds
27+ /// within that second.
28+ pub fn new ( sec : u64 , nsec : u64 ) -> Result < Self > {
29+ Ok ( Self {
30+ t : bindings:: timespec64 {
31+ tv_sec : sec. try_into ( ) ?,
32+ tv_nsec : nsec. try_into ( ) ?,
33+ } ,
34+ } )
35+ }
36+ }
37+
38+ impl From < Time > for bindings:: timespec64 {
39+ fn from ( v : Time ) -> Self {
40+ v. t
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments