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 time
feature.
[dependencies]
yasna = { version = "*", features = ["time"] }
§Examples
use yasna::models::GeneralizedTime;
let datetime =
*GeneralizedTime::parse(b"19851106210627.3Z").unwrap().datetime();
assert_eq!(datetime.year(), 1985);
assert_eq!(datetime.month() as u8, 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§
source§impl 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_offset(buf: &[u8], default_offset: UtcOffset) -> Option<Self>
pub fn parse_with_offset(buf: &[u8], default_offset: UtcOffset) -> 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(datetime: OffsetDateTime) -> Self
pub fn from_datetime(datetime: OffsetDateTime) -> Self
Constructs GeneralizedTime
from an OffsetDateTime
.
§Panics
Panics when GeneralizedTime can’t represent the datetime. That is:
- The year is not between 0 and 9999.
sourcepub fn from_datetime_opt(datetime: OffsetDateTime) -> Option<Self>
pub fn from_datetime_opt(datetime: OffsetDateTime) -> Option<Self>
Constructs GeneralizedTime
from an OffsetDateTime
.
§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(
datetime: OffsetDateTime,
sub_nano: &[u8],
) -> Self
pub fn from_datetime_and_sub_nano( datetime: OffsetDateTime, sub_nano: &[u8], ) -> Self
Constructs GeneralizedTime
from an OffsetDateTime
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(
datetime: OffsetDateTime,
sub_nano: &[u8],
) -> Option<Self>
pub fn from_datetime_and_sub_nano_opt( datetime: OffsetDateTime, sub_nano: &[u8], ) -> Option<Self>
Constructs GeneralizedTime
from an OffsetDateTime
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) -> &OffsetDateTime
pub fn datetime(&self) -> &OffsetDateTime
Returns the OffsetDateTime
it represents.
Leap seconds and sub-nanoseconds digits will be discarded.
Trait Implementations§
source§impl BERDecodable for GeneralizedTime
impl BERDecodable for GeneralizedTime
source§fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
source§impl Clone for GeneralizedTime
impl Clone for GeneralizedTime
source§fn clone(&self) -> GeneralizedTime
fn clone(&self) -> GeneralizedTime
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl DEREncodable for GeneralizedTime
impl DEREncodable for GeneralizedTime
source§fn encode_der(&self, writer: DERWriter<'_>)
fn encode_der(&self, writer: DERWriter<'_>)
source§impl Debug for GeneralizedTime
impl Debug for GeneralizedTime
source§impl Hash for GeneralizedTime
impl Hash for GeneralizedTime
source§impl Ord for GeneralizedTime
impl Ord for GeneralizedTime
source§fn cmp(&self, other: &GeneralizedTime) -> Ordering
fn cmp(&self, other: &GeneralizedTime) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for GeneralizedTime
impl PartialEq for GeneralizedTime
source§fn eq(&self, other: &GeneralizedTime) -> bool
fn eq(&self, other: &GeneralizedTime) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for GeneralizedTime
impl PartialOrd for GeneralizedTime
source§fn partial_cmp(&self, other: &GeneralizedTime) -> Option<Ordering>
fn partial_cmp(&self, other: &GeneralizedTime) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for GeneralizedTime
impl StructuralPartialEq for GeneralizedTime
Auto Trait Implementations§
impl Freeze for GeneralizedTime
impl RefUnwindSafe for GeneralizedTime
impl Send for GeneralizedTime
impl Sync for GeneralizedTime
impl Unpin for GeneralizedTime
impl UnwindSafe for GeneralizedTime
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)