[−][src]Struct yasna::models::GeneralizedTime
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);
Methods
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]
buf: &[u8],
default_tz: &Tz
) -> Option<Self>
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]
datetime: &DateTime<Tz>,
sub_nano: &[u8]
) -> Self
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]
datetime: &DateTime<Tz>,
sub_nano: &[u8]
) -> Option<Self>
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]
fn decode_ber(reader: BERReader) -> ASN1Result<Self>[src]
impl DEREncodable for GeneralizedTime[src]
fn encode_der(&self, writer: DERWriter)[src]
impl Clone for GeneralizedTime[src]
fn clone(&self) -> GeneralizedTime[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Eq for GeneralizedTime[src]
impl Ord for GeneralizedTime[src]
fn cmp(&self, other: &GeneralizedTime) -> Ordering[src]
fn max(self, other: Self) -> Self1.21.0[src]
fn min(self, other: Self) -> Self1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self[src]
impl PartialEq<GeneralizedTime> for GeneralizedTime[src]
fn eq(&self, other: &GeneralizedTime) -> bool[src]
fn ne(&self, other: &GeneralizedTime) -> bool[src]
impl PartialOrd<GeneralizedTime> for GeneralizedTime[src]
fn partial_cmp(&self, other: &GeneralizedTime) -> Option<Ordering>[src]
fn lt(&self, other: &GeneralizedTime) -> bool[src]
fn le(&self, other: &GeneralizedTime) -> bool[src]
fn gt(&self, other: &GeneralizedTime) -> bool[src]
fn ge(&self, other: &GeneralizedTime) -> bool[src]
impl Debug for GeneralizedTime[src]
impl Hash for GeneralizedTime[src]
Auto Trait Implementations
impl Send for GeneralizedTime
impl Sync for GeneralizedTime
impl Unpin for GeneralizedTime
impl UnwindSafe for GeneralizedTime
impl RefUnwindSafe for GeneralizedTime
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> From<T> for T[src]
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,