pub struct MailDate { /* private fields */ }Expand description
A point in time with a zone offset, from an email Date or Received
field (RFC 5322 section 3.3).
§Examples
use parse_net::MailDate;
let d = MailDate::parse(b"Wed, 21 Oct 2026 17:38:00 +0200", false)?;
assert_eq!(d.offset_minutes(), 120);
let mut buf = [0u8; 64];
let mut out = parse_net::SliceSink::new(&mut buf);
d.write_to(&mut out).expect("room");
assert_eq!(out.written(), b"Wed, 21 Oct 2026 17:38:00 +0200");
assert!(MailDate::parse(b"21 Oct 26 17:38 EDT", false).is_err());
assert_eq!(MailDate::parse(b"21 Oct 26 17:38 EDT", true)?.offset_minutes(), -240);Implementations§
Source§impl MailDate
impl MailDate
Sourcepub fn new(utc_secs: i64, offset_minutes: i16) -> Result<Self, ParseError>
pub fn new(utc_secs: i64, offset_minutes: i16) -> Result<Self, ParseError>
The time utc_secs (seconds since the Unix epoch) shown in the zone
offset_minutes east of UTC.
§Errors
ErrorKind::OutOfRange for an offset beyond plus or minus 99:59 or
a local time outside years 1 to 9999.
§Examples
use parse_net::MailDate;
let d = MailDate::new(0, -300)?;
assert_eq!(&d.format().0[..d.format().1], b"Wed, 31 Dec 1969 19:00:00 -0500");
assert!(MailDate::new(0, 6000).is_err());Sourcepub const fn utc(self) -> i64
pub const fn utc(self) -> i64
Seconds since the Unix epoch, UTC.
§Examples
let d = parse_net::MailDate::parse(b"1 Jan 1970 01:00:00 +0100", false)?;
assert_eq!(d.utc(), 0);Sourcepub const fn offset_minutes(self) -> i16
pub const fn offset_minutes(self) -> i16
The zone offset in minutes east of UTC (0 when unknown).
§Examples
let d = parse_net::MailDate::parse(b"21 Oct 2026 08:08:00 -0330", false)?;
assert_eq!(d.offset_minutes(), -210);Sourcepub const fn offset_unknown(self) -> bool
pub const fn offset_unknown(self) -> bool
Whether the zone was -0000: the time is UTC and the local zone is
unknown (RFC 5322 section 3.3), or an obsolete military zone, which
the RFC says to read the same way.
§Examples
use parse_net::MailDate;
assert!(MailDate::parse(b"21 Oct 2026 17:38:00 -0000", false)?.offset_unknown());
assert!(!MailDate::parse(b"21 Oct 2026 17:38:00 +0000", false)?.offset_unknown());Sourcepub const fn leap_second(self) -> bool
pub const fn leap_second(self) -> bool
Whether the seconds were 60 (read as 59).
§Examples
use parse_net::MailDate;
let leap = MailDate::parse(b"31 Dec 2016 23:59:60 +0000", false)?;
assert!(leap.leap_second());
assert_eq!(leap.utc(), MailDate::parse(b"31 Dec 2016 23:59:59 +0000", false)?.utc());Sourcepub fn format(self) -> ([u8; 31], usize)
pub fn format(self) -> ([u8; 31], usize)
The value as Wed, 21 Oct 2026 17:38:00 +0200: weekday, two-digit
day, four-digit year, seconds, and a numeric zone (-0000 when the
offset is unknown). Returns the bytes and their length (always 31).
§Examples
let d = parse_net::MailDate::parse(b"21 oct 2026 17:38 +0200", false)?;
let (bytes, len) = d.format();
assert_eq!(&bytes[..len], b"Wed, 21 Oct 2026 17:38:00 +0200");Sourcepub fn write_to(self, out: &mut impl Sink) -> Result<(), WriteError>
pub fn write_to(self, out: &mut impl Sink) -> Result<(), WriteError>
Writes format’s text.
§Errors
WriteError::Full; nothing is written when the sink reports its
room.
§Examples
use parse_net::{MailDate, SliceSink, WriteError};
let d = MailDate::new(0, 0).expect("in range");
let mut buf = [0u8; 40];
let mut out = SliceSink::new(&mut buf);
d.write_to(&mut out)?;
assert_eq!(out.written(), b"Thu, 01 Jan 1970 00:00:00 +0000");
assert_eq!(d.write_to(&mut SliceSink::new(&mut [0u8; 10])), Err(WriteError::Full));Sourcepub fn parse(value: &[u8], obsolete: bool) -> Result<Self, ParseError>
pub fn parse(value: &[u8], obsolete: bool) -> Result<Self, ParseError>
Parses an RFC 5322 date-time. Names are case-insensitive (RFC 5234
quoted strings); comments and folding whitespace may separate the
tokens. With obsolete, also the section 4.3 forms: two- and
three-digit years (below 50 are 20xx, others 19xx; three digits add
1900, D-036), UT, GMT, the North American zones, and the military
zones (read as -0000).
§Errors
ErrorKind::InvalidDate (a field out of range, a missing token, an
obsolete form without obsolete); ErrorKind::WeekdayMismatch;
ErrorKind::OutOfRange (a year outside 1 to 9999);
ErrorKind::TrailingData; ErrorKind::UnbalancedComment;
ErrorKind::CommentTooDeep; ErrorKind::BareCr and
ErrorKind::LineFeed for a line break that is not folding.
§Examples
use parse_net::{ErrorKind, MailDate};
let d = MailDate::parse(b"1 jan 2026 00:00 (morning) -0000", false)?;
assert!(d.offset_unknown());
assert_eq!(MailDate::parse(b"Mon, 21 Oct 2026 17:38:00 +0200", false).unwrap_err().kind(), ErrorKind::WeekdayMismatch);