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

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.

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.

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.

Returns the datetime it represents.

Returns ASN.1 canonical representation of the datetime as Vec<u8>.

Returns ASN.1 canonical representation of the datetime as String.

Trait Implementations

Reads an ASN.1 value from BERReader and converts it to Self. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Writes the value as an DER-encoded ASN.1 value. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.