Struct yasna::models::GeneralizedTime[][src]

pub struct GeneralizedTime { /* fields omitted */ }

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

impl GeneralizedTime[src]

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

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.

pub fn parse_with_timezone<Tz: TimeZone>(
    buf: &[u8],
    default_tz: &Tz
) -> Option<Self>
[src]

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.

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

Constructs GeneralizedTime from a datetime.

Panics

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

  • The year is not between 0 and 9999.

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

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.

pub fn from_datetime_and_sub_nano<Tz: TimeZone>(
    datetime: &DateTime<Tz>,
    sub_nano: &[u8]
) -> Self
[src]

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.

pub fn from_datetime_and_sub_nano_opt<Tz: TimeZone>(
    datetime: &DateTime<Tz>,
    sub_nano: &[u8]
) -> Option<Self>
[src]

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.

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

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

pub fn sub_nano(&self) -> &[u8][src]

Returns sub-nanoseconds digits of the datetime.

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 GeneralizedTime[src]

impl Clone for GeneralizedTime[src]

impl DEREncodable for GeneralizedTime[src]

impl Debug for GeneralizedTime[src]

impl Eq for GeneralizedTime[src]

impl Hash for GeneralizedTime[src]

impl Ord for GeneralizedTime[src]

impl PartialEq<GeneralizedTime> for GeneralizedTime[src]

impl PartialOrd<GeneralizedTime> for GeneralizedTime[src]

impl StructuralEq for GeneralizedTime[src]

impl StructuralPartialEq for GeneralizedTime[src]

Auto Trait Implementations

impl RefUnwindSafe for GeneralizedTime

impl Send for GeneralizedTime

impl Sync for GeneralizedTime

impl Unpin for GeneralizedTime

impl UnwindSafe for GeneralizedTime

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.