Parsing a RFC2822 date from Chrono #20

Closed
opened 2017-09-09 09:07:23 +12:00 by eminence · 3 comments
eminence commented 2017-09-09 09:07:23 +12:00 (Migrated from github.com)

Chrono's to_rfc2822 method will return a date string like the following:

Fri,  8 Sep 2017 20:46:39 +0000

This is unparseable by email-format, seemingly because the single digit (8) for the day-of-month:

thread 'main' panicked at 'called Result::unwrap() on an Err value: "DateTime" Not Found', src\libcore\result.rs:906:4

I've been reading RFC2822, and do be honest I can't tell if a single-digit field is allowed. Do you think this is a email-format parsing problem? Or a Chrono formatting problem?

Chrono's [`to_rfc2822`](https://docs.rs/chrono/0.4.0/chrono/struct.DateTime.html#method.to_rfc2822) method will return a date string like the following: Fri, 8 Sep 2017 20:46:39 +0000 This is unparseable by email-format, seemingly because the single digit (`8`) for the day-of-month: > thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "DateTime" Not Found', src\libcore\result.rs:906:4 I've been reading RFC2822, and do be honest I can't tell if a single-digit field is allowed. Do you think this is a email-format parsing problem? Or a Chrono formatting problem?
eminence commented 2017-09-09 09:11:06 +12:00 (Migrated from github.com)

After a little more research, the day field is defined as (via RFC2822 section 3.3):

day             =   ([FWS] 1*2DIGIT FWS) / obs-day

I had to look up this notational format in RFC 2234 to find that it means this:

The operator "*" preceding an element indicates repetition. The full
   form is:

        <a>*<b>element

   where <a> and <b> are optional decimal values, indicating at least
   <a> and at most <b> occurrences of element.

So RFC2822 (and RFC5322) allow for a single-digit date.

After a little more research, the `day` field is defined as (via RFC2822 section 3.3): day = ([FWS] 1*2DIGIT FWS) / obs-day I had to look up this notational format in RFC 2234 to find that it means this: ``` The operator "*" preceding an element indicates repetition. The full form is: <a>*<b>element where <a> and <b> are optional decimal values, indicating at least <a> and at most <b> occurrences of element. ``` So RFC2822 (and RFC5322) allow for a single-digit date.
mikedilger commented 2017-09-09 09:16:01 +12:00 (Migrated from github.com)

Aha! I was reading that ABNF as if 2DIGIT was a single token, and so there could be only a single 2DIGIT. I will make the change.

Aha! I was reading that ABNF as if `2DIGIT` was a single token, and so there could be only a single `2DIGIT`. I will make the change.
eminence commented 2017-09-09 09:24:28 +12:00 (Migrated from github.com)

I just put together a quick PR for this issue, if you want it

I just put together a quick PR for this issue, if you want it
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mikedilger/email-format#20
No description provided.