Skip to main content

HttpDate

Struct HttpDate 

Source
pub struct HttpDate { /* private fields */ }
Expand description

A point in time with one-second resolution, from year 1 to year 9999, UTC; the value of HTTP-date fields (Date, Last-Modified, Expires).

§Examples

use parse_net::HttpDate;

let d = HttpDate::from_unix(0)?;
assert_eq!(&d.format(), b"Thu, 01 Jan 1970 00:00:00 GMT");
assert!(HttpDate::from_unix(HttpDate::MAX.unix() + 1).is_err());

Implementations§

Source§

impl HttpDate

Source

pub const MIN: Self

0001-01-01T00:00:00Z.

Source

pub const MAX: Self

9999-12-31T23:59:59Z.

Source

pub const fn from_unix(secs: i64) -> Result<Self, ParseError>

The date secs seconds after the Unix epoch (negative before 1970).

§Errors

ErrorKind::OutOfRange outside years 1 to 9999.

Source

pub const fn unix(self) -> i64

Seconds since the Unix epoch.

Source

pub fn civil(self) -> Civil

The broken-down UTC time.

Source

pub fn format(self) -> [u8; 29]

The IMF-fixdate text, Sun, 06 Nov 1994 08:49:37 GMT.

Source

pub fn write_to(self, out: &mut impl Sink) -> Result<(), WriteError>

Writes format into out.

§Errors

WriteError::Full.

Source

pub fn parse_imf_fixdate(value: &[u8]) -> Result<Self, ParseError>

Parses exactly an IMF-fixdate (29 bytes after OWS), the only format senders may generate. Needs no clock.

§Errors

ErrorKind::InvalidDate, ErrorKind::WeekdayMismatch, ErrorKind::OutOfRange (year 0000), ErrorKind::TrailingData.

Source

pub fn parse_at(value: &[u8], now: i64) -> Result<Self, ParseError>

Parses an HTTP-date in any of its three formats.

The RFC 850 two-digit year is resolved against now (Unix seconds): a date more than 50 years after now is taken as the most recent past year with the same last two digits, and a date 50 years or more before now moves forward a century, so the year lands in the hundred years around now. Names are case-sensitive, only GMT is accepted, and the weekday must agree with the date.

§Errors

ErrorKind::InvalidDate, ErrorKind::WeekdayMismatch, ErrorKind::OutOfRange, ErrorKind::TrailingData.

Source

pub fn parse_at_with( value: &[u8], now: i64, limits: &Limits, ) -> Result<Self, ParseError>

As parse_at, with Limits::allow_leap_second taken from limits.

§Errors

As parse_at.

Source

pub fn parse_detailed( value: &[u8], now: i64, ) -> Result<(Self, DateFormat), ParseError>

As parse_at, also reporting the format seen.

§Errors

As parse_at.

§Examples
use parse_net::{DateFormat, HttpDate};

let (_, fmt) = HttpDate::parse_detailed(b"Sunday, 06-Nov-94 08:49:37 GMT", 1_792_540_800)?;
assert_eq!(fmt, DateFormat::Rfc850);
Source

pub fn now() -> Self

Available on crate feature std only.

The current time from the system clock, clamped to the supported range.

Source

pub fn from_system_time(t: SystemTime) -> Result<Self, ParseError>

Available on crate feature std only.

The date of a SystemTime, truncated to whole seconds toward the past.

§Errors

ErrorKind::OutOfRange outside years 1 to 9999.

Source

pub fn to_system_time(self) -> Option<SystemTime>

Available on crate feature std only.

The date as a SystemTime, or None when the platform’s clock type cannot represent it (Windows cannot go before the year 1601).

Trait Implementations§

Source§

impl Clone for HttpDate

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for HttpDate

Source§

impl Debug for HttpDate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for HttpDate

Source§

impl Hash for HttpDate

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for HttpDate

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for HttpDate

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for HttpDate

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for HttpDate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.