pub struct DateTime {
year: u16,
month: u8,
day: u8,
hour: u8,
minutes: u8,
seconds: u8,
unix_duration: Duration,
}Expand description
Date-and-time type shared by multiple ASN.1 types
(e.g. GeneralizedTime, UTCTime).
Following conventions from RFC 5280, this type is always Z-normalized
(i.e. represents a UTC time). However, it isn’t named “UTC time” in order
to prevent confusion with ASN.1 UTCTime.
Fields§
§year: u16Full year (e.g. 2000).
Must be >=1970 to permit positive conversions to Unix time.
month: u8Month (1-12)
day: u8Day of the month (1-31)
hour: u8Hour (0-23)
minutes: u8Minutes (0-59)
seconds: u8Seconds (0-59)
unix_duration: DurationDuration since the Unix epoch.
Implementations§
Source§impl DateTime
impl DateTime
Sourcepub const INFINITY: DateTime
pub const INFINITY: DateTime
This is the maximum date represented by the DateTime
This corresponds to: 9999-12-31T23:59:59Z
Sourcepub const fn new(
year: u16,
month: u8,
day: u8,
hour: u8,
minutes: u8,
seconds: u8,
) -> Result<Self>
pub const fn new( year: u16, month: u8, day: u8, hour: u8, minutes: u8, seconds: u8, ) -> Result<Self>
Create a new DateTime from the given UTC time components.
§Errors
Returns Error with ErrorKind::DateTime in the event the date is invalid.
Sourcepub(crate) const fn from_ymd_hms(
year: u16,
month: u8,
day: u8,
hour: u8,
minutes: u8,
seconds: u8,
) -> Option<Self>
pub(crate) const fn from_ymd_hms( year: u16, month: u8, day: u8, hour: u8, minutes: u8, seconds: u8, ) -> Option<Self>
Create a new DateTime from the given UTC time components.
Returns None if the value is outside the supported date range.
Sourcepub fn from_unix_duration(unix_duration: Duration) -> Result<Self>
pub fn from_unix_duration(unix_duration: Duration) -> Result<Self>
Sourcepub fn unix_duration(&self) -> Duration
pub fn unix_duration(&self) -> Duration
Compute Duration since UNIX_EPOCH from the given calendar date.
Sourcepub fn from_system_time(time: SystemTime) -> Result<Self>
pub fn from_system_time(time: SystemTime) -> Result<Self>
Sourcepub fn to_system_time(&self) -> SystemTime
pub fn to_system_time(&self) -> SystemTime
Convert to SystemTime.
Trait Implementations§
Source§impl<'a> DecodeValue<'a> for DateTime
impl<'a> DecodeValue<'a> for DateTime
Source§impl EncodeValue for DateTime
impl EncodeValue for DateTime
Source§impl From<&DateTime> for GeneralizedTime
impl From<&DateTime> for GeneralizedTime
Source§impl From<&DateTime> for SystemTime
Available on crate feature std only.
impl From<&DateTime> for SystemTime
std only.Source§fn from(time: &DateTime) -> SystemTime
fn from(time: &DateTime) -> SystemTime
Source§impl From<&GeneralizedTime> for DateTime
impl From<&GeneralizedTime> for DateTime
Source§fn from(utc_time: &GeneralizedTime) -> DateTime
fn from(utc_time: &GeneralizedTime) -> DateTime
Source§impl From<DateTime> for GeneralizedTime
impl From<DateTime> for GeneralizedTime
Source§impl From<DateTime> for SystemTime
Available on crate feature std only.
impl From<DateTime> for SystemTime
std only.Source§fn from(time: DateTime) -> SystemTime
fn from(time: DateTime) -> SystemTime
Source§impl From<GeneralizedTime> for DateTime
impl From<GeneralizedTime> for DateTime
Source§fn from(utc_time: GeneralizedTime) -> DateTime
fn from(utc_time: GeneralizedTime) -> DateTime
Source§impl Ord for DateTime
impl Ord for DateTime
Source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
Source§impl TryFrom<&SystemTime> for DateTime
Available on crate feature std only.
impl TryFrom<&SystemTime> for DateTime
std only.Source§impl TryFrom<SystemTime> for DateTime
Available on crate feature std only.
impl TryFrom<SystemTime> for DateTime
std only.