Skip to content

Commit

Permalink
Format day in RFC 2822 without padding (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker authored Sep 11, 2023
1 parent ccd3737 commit 084b021
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ fn test_datetime_rfc2822() {
Utc.with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap().to_rfc2822(),
"Wed, 18 Feb 2015 23:16:09 +0000"
);
assert_eq!(
Utc.with_ymd_and_hms(2015, 2, 1, 23, 16, 9).unwrap().to_rfc2822(),
"Sun, 1 Feb 2015 23:16:09 +0000"
);
// timezone +05
assert_eq!(
edt.from_local_datetime(
Expand Down
7 changes: 6 additions & 1 deletion src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,12 @@ fn write_rfc2822_inner(

w.write_str(short_weekdays(locale)[d.weekday().num_days_from_sunday() as usize])?;
w.write_str(", ")?;
write_hundreds(w, d.day() as u8)?;
let day = d.day();
if day < 10 {
w.write_char((b'0' + day as u8) as char)?;
} else {
write_hundreds(w, day as u8)?;
}
w.write_char(' ')?;
w.write_str(short_months(locale)[d.month0() as usize])?;
w.write_char(' ')?;
Expand Down

0 comments on commit 084b021

Please sign in to comment.