// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // Copyright by contributors to this project. // SPDX-License-Identifier: (Apache-2.0 OR MIT)
use core::time::Duration; use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
#[cfg(target_arch = "wasm32")] use wasm_bindgen::prelude::*;
/// Wasm-compatible representation of a timestamp. /// /// This type represents a point in time after 1970. The precision is seconds. /// /// Since `MlsTime` always represents a timestamp after 1970, it can be trivially /// converted to/from a standard library [`Duration`] value (measuring the time since /// the start of the Unix epoch). #[derive(
Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, MlsSize, MlsEncode, MlsDecode,
)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[repr(transparent)] pubstruct MlsTime {
seconds: u64,
}
impl MlsTime { /// Create a timestamp from a duration since unix epoch. pubfn from_duration_since_epoch(duration: Duration) -> MlsTime { Self::from(duration)
}
/// Number of seconds since the unix epoch. pubfn seconds_since_epoch(&self) -> u64 { self.seconds
}
}
impl core::ops::Sub<MlsTime> for MlsTime { type Output = Duration;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.