Struct yasna::models::UTCTime[][src]

pub struct UTCTime { /* fields omitted */ }

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

impl UTCTime[src]

pub fn parse(buf: &[u8]) -> Option<Self>[src]

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.

pub fn from_datetime<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Self[src]

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.

pub fn from_datetime_opt<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Option<Self>[src]

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.

pub fn datetime(&self) -> &DateTime<Utc>[src]

Returns the datetime it represents.

pub fn to_bytes(&self) -> Vec<u8>[src]

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

pub fn to_string(&self) -> String[src]

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

Trait Implementations

impl BERDecodable for UTCTime[src]

impl Clone for UTCTime[src]

impl DEREncodable for UTCTime[src]

impl Debug for UTCTime[src]

impl Eq for UTCTime[src]

impl Hash for UTCTime[src]

impl Ord for UTCTime[src]

impl PartialEq<UTCTime> for UTCTime[src]

impl PartialOrd<UTCTime> for UTCTime[src]

impl StructuralEq for UTCTime[src]

impl StructuralPartialEq for UTCTime[src]

Auto Trait Implementations

impl RefUnwindSafe for UTCTime

impl Send for UTCTime

impl Sync for UTCTime

impl Unpin for UTCTime

impl UnwindSafe for UTCTime

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.