pub struct UTCTime { /* private fields */ }
Expand description
Date and time between 1950-01-01T00:00:00Z and 2049-12-31T23:59:59Z. It cannot express fractional seconds and leap seconds. It doesn’t carry timezone information.
Corresponds to ASN.1 UTCTime type. Often used in conjunction with
GeneralizedTime
.
§Features
This struct is enabled by time
feature.
[dependencies]
yasna = { version = "*", features = ["time"] }
§Examples
use yasna::models::UTCTime;
let datetime = *UTCTime::parse(b"8201021200Z").unwrap().datetime();
assert_eq!(datetime.year(), 1982);
assert_eq!(datetime.month() as u8, 1);
assert_eq!(datetime.day(), 2);
assert_eq!(datetime.hour(), 12);
assert_eq!(datetime.minute(), 0);
assert_eq!(datetime.second(), 0);
assert_eq!(datetime.nanosecond(), 0);
Implementations§
source§impl UTCTime
impl UTCTime
sourcepub fn parse(buf: &[u8]) -> Option<Self>
pub fn parse(buf: &[u8]) -> Option<Self>
Parses ASN.1 string representation of UTCTime.
§Examples
use yasna::models::UTCTime;
let datetime = UTCTime::parse(b"000229123456Z").unwrap();
assert_eq!(&datetime.to_string(), "000229123456Z");
§Errors
It returns None
if the given string does not specify a correct
datetime.
§Interpretation
While neither X.680 nor X.690 specify interpretation of 2-digits year, X.501 specifies that UTCTime in Time shall be interpreted as between 1950 and 2049. This method parses the string according to the X.501 rule.
sourcepub fn from_datetime(datetime: OffsetDateTime) -> Self
pub fn from_datetime(datetime: OffsetDateTime) -> Self
Constructs UTCTime
from an OffsetDateTime
.
§Panics
Panics when UTCTime can’t represent the datetime. That is:
- The year is not between 1950 and 2049.
- It is in a leap second.
- It has a non-zero nanosecond value.
sourcepub fn from_datetime_opt(datetime: OffsetDateTime) -> Option<Self>
pub fn from_datetime_opt(datetime: OffsetDateTime) -> Option<Self>
Constructs UTCTime
from an OffsetDateTime
.
§Errors
It returns None
when UTCTime can’t represent the datetime. That is:
- The year is not between 1950 and 2049.
- It is in a leap second.
- It has a non-zero nanosecond value.
sourcepub fn datetime(&self) -> &OffsetDateTime
pub fn datetime(&self) -> &OffsetDateTime
Returns the OffsetDateTime
it represents.
Trait Implementations§
source§impl BERDecodable for UTCTime
impl BERDecodable for UTCTime
source§fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
source§impl DEREncodable for UTCTime
impl DEREncodable for UTCTime
source§fn encode_der(&self, writer: DERWriter<'_>)
fn encode_der(&self, writer: DERWriter<'_>)
source§impl Ord for UTCTime
impl Ord for UTCTime
source§impl PartialEq for UTCTime
impl PartialEq for UTCTime
source§impl PartialOrd for UTCTime
impl PartialOrd for UTCTime
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more