pub struct GeneralizedTime { /* private fields */ }
Expand description

Date and time between 0000-01-01T00:00:00Z and 9999-12-31T23:59:60.999…Z.

It can contain arbitrary length of decimal fractional seconds. However, it doesn’t carry accuracy information. It can also contain leap seconds.

The datetime is canonicalized to UTC. It doesn’t carry timezone information.

Corresponds to ASN.1 GeneralizedTime type. Often used in conjunction with UTCTime.

Features

This struct is enabled by chrono feature.

[dependencies]
yasna = { version = "*", features = ["chrono"] }

Examples

use yasna::models::GeneralizedTime;
use chrono::{Datelike,Timelike};
let datetime =
    *GeneralizedTime::parse(b"19851106210627.3Z").unwrap().datetime();
assert_eq!(datetime.year(), 1985);
assert_eq!(datetime.month(), 11);
assert_eq!(datetime.day(), 6);
assert_eq!(datetime.hour(), 21);
assert_eq!(datetime.minute(), 6);
assert_eq!(datetime.second(), 27);
assert_eq!(datetime.nanosecond(), 300_000_000);

Implementations

Parses ASN.1 string representation of GeneralizedTime.

Examples
use yasna::models::GeneralizedTime;
let datetime = GeneralizedTime::parse(b"1985110621.14159Z").unwrap();
assert_eq!(&datetime.to_string(), "19851106210829.724Z");
Errors

It returns None if the given string does not specify a correct datetime.

Parses ASN.1 string representation of GeneralizedTime, with the default timezone for local time given.

Examples
use yasna::models::GeneralizedTime;
let datetime = GeneralizedTime::parse(b"1985110621.14159Z").unwrap();
assert_eq!(&datetime.to_string(), "19851106210829.724Z");
Errors

It returns None if the given string does not specify a correct datetime.

Constructs GeneralizedTime from a datetime.

Panics

Panics when GeneralizedTime can’t represent the datetime. That is:

  • The year is not between 0 and 9999.

Constructs GeneralizedTime from a datetime.

Errors

It returns None when GeneralizedTime can’t represent the datetime. That is:

  • The year is not between 0 and 9999.

Constructs GeneralizedTime from a datetime and sub-nanoseconds digits.

Panics

Panics when GeneralizedTime can’t represent the datetime. That is:

  • The year is not between 0 and 9999.

It also panics if sub_nano contains a non-digit character.

Constructs GeneralizedTime from a datetime and sub-nanoseconds digits.

Errors

It returns None when GeneralizedTime can’t represent the datetime. That is:

  • The year is not between 0 and 9999.

It also returns None if sub_nano contains a non-digit character.

Returns the datetime it represents, discarding sub-nanoseconds digits.

Returns sub-nanoseconds digits of the datetime.

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.