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
][generaliedtime].
Features
This struct is enabled by chrono
feature.
[dependencies]
yasna = { version = "*", features = ["chrono"] }
Examples
use yasna::models::UTCTime;
use chrono::{Datelike,Timelike};
let datetime = *UTCTime::parse(b"8201021200Z").unwrap().datetime();
assert_eq!(datetime.year(), 1982);
assert_eq!(datetime.month(), 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
sourceimpl 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<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Self
pub fn from_datetime<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Self
Constructs UTCTime
from a datetime.
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<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Option<Self>
pub fn from_datetime_opt<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Option<Self>
Constructs UTCTime
from a datetime.
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.
Trait Implementations
sourceimpl BERDecodable for UTCTime
impl BERDecodable for UTCTime
sourcefn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
sourceimpl DEREncodable for UTCTime
impl DEREncodable for UTCTime
sourcefn encode_der(&self, writer: DERWriter<'_>)
fn encode_der(&self, writer: DERWriter<'_>)
sourceimpl Hash for UTCTime
impl Hash for UTCTime
sourcefn hash<__H: Hasher>(&self, state: &mut __H)
fn hash<__H: Hasher>(&self, state: &mut __H)
Hasher
]. Read more1.3.0fn hash_slice<H>(data: &[Self], state: &mut H)where
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H)where
H: Hasher,
Hasher
]. Read more