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
use std::time::{SystemTime, UNIX_EPOCH};
pub trait Mortal {
fn timeout(&self) -> u128;
fn expired(&self) -> bool {
now() > self.timeout()
}
fn terminate(&mut self);
fn terminated(&self) -> bool;
fn remaining_time(&self) -> u128 {
return (self.timeout() - now()) / 1000;
}
}
pub fn now() -> u128 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis()
}
pub(crate) fn etsi_now() -> u128 {
etsi_timestamp(now())
}
pub(crate) fn timestamp(etsi_timestamp: u128) -> u128 {
etsi_timestamp + 1072915195000
}
pub fn etsi_timestamp(timestamp: u128) -> u128 {
timestamp - 1072915195000
}