Skip to main content

MailDate

Struct MailDate 

Source
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

Source

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());
Source

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);
Source

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);
Source

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());
Source

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());
Source

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");
Source

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));
Source

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);

Trait Implementations§

Source§

impl Clone for MailDate

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 MailDate

Source§

impl Debug for MailDate

Source§

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

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

impl Eq for MailDate

Source§

impl Hash for MailDate

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 PartialEq for MailDate

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 StructuralPartialEq for MailDate

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.