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
impl HttpDate
Sourcepub const fn from_unix(secs: i64) -> Result<Self, ParseError>
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.
Sourcepub fn parse_imf_fixdate(value: &[u8]) -> Result<Self, ParseError>
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.
Sourcepub fn parse_at(value: &[u8], now: i64) -> Result<Self, ParseError>
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.
Sourcepub fn parse_at_with(
value: &[u8],
now: i64,
limits: &Limits,
) -> Result<Self, ParseError>
pub fn parse_at_with( value: &[u8], now: i64, limits: &Limits, ) -> Result<Self, ParseError>
Sourcepub fn parse_detailed(
value: &[u8],
now: i64,
) -> Result<(Self, DateFormat), ParseError>
pub fn parse_detailed( value: &[u8], now: i64, ) -> Result<(Self, DateFormat), ParseError>
Sourcepub fn now() -> Self
Available on crate feature std only.
pub fn now() -> Self
std only.The current time from the system clock, clamped to the supported range.
Sourcepub fn from_system_time(t: SystemTime) -> Result<Self, ParseError>
Available on crate feature std only.
pub fn from_system_time(t: SystemTime) -> Result<Self, ParseError>
std only.The date of a SystemTime, truncated to whole seconds toward the
past.
§Errors
ErrorKind::OutOfRange outside years 1 to 9999.
Sourcepub fn to_system_time(self) -> Option<SystemTime>
Available on crate feature std only.
pub fn to_system_time(self) -> Option<SystemTime>
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).