pub struct DateTime {
pub year: u16,
pub month: u8,
pub day: u8,
pub hour: u8,
pub minute: u8,
pub second: u8,
pub tz_offset_minutes: i16,
}Expand description
Date-time with timezone offset preserved.
§References
- RFC 5322 Section 3.3 (date-time specification)
Fields§
§year: u16Year (e.g., 2025).
month: u8Month (1–12).
day: u8Day of month (1–31).
hour: u8Hour (0–23).
minute: u8Minute (0–59).
second: u8Second (0–59).
tz_offset_minutes: i16Timezone offset from UTC in minutes (e.g., +0530 → 330, −0800 → −480).
Implementations§
Source§impl DateTime
impl DateTime
Sourcepub fn to_unix_timestamp(&self) -> i64
pub fn to_unix_timestamp(&self) -> i64
Converts this date-time to a Unix timestamp (seconds since 1970-01-01T00:00:00Z).
The timezone offset is applied so the result is always UTC-based. Uses the same civil-to-days algorithm as the builder.
§References
- RFC 5322 Section 3.3
Sourcepub fn from_unix_timestamp(timestamp: i64, tz_offset_minutes: i16) -> Self
pub fn from_unix_timestamp(timestamp: i64, tz_offset_minutes: i16) -> Self
Creates a DateTime from a Unix timestamp (seconds since epoch) and a
timezone offset in minutes.
§References
- RFC 5322 Section 3.3
Sourcepub fn weekday(&self) -> u8
pub fn weekday(&self) -> u8
Returns the day of week for this date.
Returns 0 for Sunday, 1 for Monday, …, 6 for Saturday.
§References
- RFC 5322 Section 3.3
Sourcepub fn to_rfc5322_string(&self) -> String
pub fn to_rfc5322_string(&self) -> String
Formats this date-time as an RFC 5322 date-time string.
Produces the format: day-of-week, DD Mon YYYY HH:MM:SS ±HHMM
(e.g., "Thu, 13 Feb 2025 15:47:33 +0000").
§References
- RFC 5322 Section 3.3
Sourcepub fn to_iso8601_string(&self) -> String
pub fn to_iso8601_string(&self) -> String
Formats this date-time as an ISO 8601 / RFC 3339 string.
Produces the format: YYYY-MM-DDTHH:MM:SS±HH:MM
(e.g., "2025-02-13T15:47:33+00:00").
This format is widely used in JSON APIs and structured data exchange.
§References
- ISO 8601 (date-time representation)
- RFC 3339 (date-time on the Internet)
Sourcepub fn parse_rfc5322(input: &str) -> Option<Self>
pub fn parse_rfc5322(input: &str) -> Option<Self>
Parses an RFC 5322 date-time string into a DateTime.
Accepts: [day-of-week ","] day month year hour ":" minute [":" second] zone
Strips CFWS (comments and folding white space) before parsing, as allowed by the obsolete date syntax (RFC 5322 Section 4.3).
Returns None if the input is not a valid RFC 5322 date-time.
§References
- RFC 5322 Section 3.3
- RFC 5322 Section 4.3 (obsolete syntax)
Trait Implementations§
Source§impl FromStr for DateTime
impl FromStr for DateTime
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses an RFC 5322 date-time string into a DateTime.
Accepts: [day-of-week ","] day month year hour ":" minute [":" second] zone
This enables the ergonomic "Thu, 13 Feb 2025 15:47:33 +0000".parse::<DateTime>()
pattern via the standard FromStr trait.
§References
- RFC 5322 Section 3.3
- RFC 5322 Section 4.3 (obsolete syntax)
Source§impl Hash for DateTime
impl Hash for DateTime
Source§impl Ord for DateTime
impl Ord for DateTime
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Compares two DateTime values by their UTC-normalized timestamps.