Struct yasna::models::GeneralizedTime
source · [−]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
sourceimpl GeneralizedTime
impl GeneralizedTime
sourcepub fn parse(buf: &[u8]) -> Option<Self>
pub fn parse(buf: &[u8]) -> Option<Self>
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.
sourcepub fn parse_with_timezone<Tz: TimeZone>(
buf: &[u8],
default_tz: &Tz
) -> Option<Self>
pub fn parse_with_timezone<Tz: TimeZone>(
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.
sourcepub fn from_datetime<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Self
pub fn from_datetime<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Self
Constructs GeneralizedTime
from a datetime.
Panics
Panics when GeneralizedTime can’t represent the datetime. That is:
- The year is not between 0 and 9999.
sourcepub fn from_datetime_opt<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Option<Self>
pub fn from_datetime_opt<Tz: TimeZone>(datetime: &DateTime<Tz>) -> Option<Self>
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.
sourcepub fn from_datetime_and_sub_nano<Tz: TimeZone>(
datetime: &DateTime<Tz>,
sub_nano: &[u8]
) -> Self
pub fn from_datetime_and_sub_nano<Tz: TimeZone>(
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.
sourcepub fn from_datetime_and_sub_nano_opt<Tz: TimeZone>(
datetime: &DateTime<Tz>,
sub_nano: &[u8]
) -> Option<Self>
pub fn from_datetime_and_sub_nano_opt<Tz: TimeZone>(
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.
sourcepub fn datetime(&self) -> &DateTime<Utc>
pub fn datetime(&self) -> &DateTime<Utc>
Returns the datetime it represents, discarding sub-nanoseconds digits.
sourcepub fn sub_nano(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn sub_nano(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Returns sub-nanoseconds digits of the datetime.
Trait Implementations
sourceimpl BERDecodable for GeneralizedTime
impl BERDecodable for GeneralizedTime
sourcefn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
sourceimpl Clone for GeneralizedTime
impl Clone for GeneralizedTime
sourcefn clone(&self) -> GeneralizedTime
fn clone(&self) -> GeneralizedTime
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl DEREncodable for GeneralizedTime
impl DEREncodable for GeneralizedTime
sourcefn encode_der(&self, writer: DERWriter<'_>)
fn encode_der(&self, writer: DERWriter<'_>)
sourceimpl Debug for GeneralizedTime
impl Debug for GeneralizedTime
sourceimpl Hash for GeneralizedTime
impl Hash for GeneralizedTime
sourceimpl Ord for GeneralizedTime
impl Ord for GeneralizedTime
sourcefn cmp(&self, other: &GeneralizedTime) -> Ordering
fn cmp(&self, other: &GeneralizedTime) -> Ordering
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialEq<GeneralizedTime> for GeneralizedTime
impl PartialEq<GeneralizedTime> for GeneralizedTime
sourcefn eq(&self, other: &GeneralizedTime) -> bool
fn eq(&self, other: &GeneralizedTime) -> bool
sourceimpl PartialOrd<GeneralizedTime> for GeneralizedTime
impl PartialOrd<GeneralizedTime> for GeneralizedTime
sourcefn partial_cmp(&self, other: &GeneralizedTime) -> Option<Ordering>
fn partial_cmp(&self, other: &GeneralizedTime) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more