We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6316b26 commit 8da3b40Copy full SHA for 8da3b40
x509-tsp/src/generalized_time_nanos.rs
@@ -37,6 +37,18 @@ impl GeneralizedTimeNanos {
37
pub fn to_unix_duration(&self) -> Duration {
38
self.datetime.unix_duration() + Duration::from_nanos(u64::from(self.nanoseconds))
39
}
40
+
41
+ /// Create a new [`GeneralizedTimeNanos`] given a [`Duration`] since
42
+ /// `UNIX_EPOCH` (a.k.a. "Unix time")
43
+ pub fn from_unix_duration(unix_duration: Duration) -> Result<Self> {
44
+ let datetime =
45
+ DateTime::from_unix_duration(unix_duration).map_err(|_| Self::TAG.value_error())?;
46
47
+ Ok(GeneralizedTimeNanos {
48
+ datetime,
49
+ nanoseconds: unix_duration.subsec_nanos(),
50
+ })
51
+ }
52
53
54
impl From<GeneralizedTime> for GeneralizedTimeNanos {
0 commit comments