time-rs / time

The most used Rust library for date and time handling.
https://time-rs.github.io
Apache License 2.0
1.1k stars 277 forks source link

Optional weekday for rfc2822 #661

Closed Mathieu-Lala closed 7 months ago

Mathieu-Lala commented 7 months ago

Given the following project:

# Cargo.toml
[package]
name = "time-test"
version = "0.1.0"
edition = "2021"

[dependencies]
time = { version = "0.3.34", features = ["parsing"] }
// src/main.rs
use time::{format_description::well_known::Rfc2822, OffsetDateTime};

fn main() {
    // ok
    OffsetDateTime::parse("Sat, 12 Jun 1993 13:25:19 GMT", &Rfc2822).unwrap();

    // thread 'main' panicked at src/main.rs:6:65:
    // called `Result::unwrap()` on an `Err` value: ParseFromDescription(InvalidComponent("weekday"))
    OffsetDateTime::parse("12 Jun 1993 13:25:19 GMT", &Rfc2822).unwrap();       
}

According to the rfc: https://datatracker.ietf.org/doc/html/rfc2822#section-3.3 Or the rfc 5322 which made rfc2822 obsolete https://datatracker.ietf.org/doc/html/rfc5322#section-3.3

The abnf syntax is:

   date-time       =   [ day-of-week "," ] date time [CFWS]

I suppose your implementation make weekday require where it should be optional.

jhpratt commented 7 months ago

Definitely a bug. I'll get to this in the near future.

jhpratt commented 7 months ago

Fixed on main.