Struct yasna::models::UTCTime [−][src]
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]
fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>
[src]
impl Clone for UTCTime
[src]
impl DEREncodable for UTCTime
[src]
fn encode_der(&self, writer: DERWriter<'_>)
[src]
impl Debug for UTCTime
[src]
impl Eq for UTCTime
[src]
impl Hash for UTCTime
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for UTCTime
[src]
fn cmp(&self, other: &UTCTime) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<UTCTime> for UTCTime
[src]
impl PartialOrd<UTCTime> for UTCTime
[src]
fn partial_cmp(&self, other: &UTCTime) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,