Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline write_rfc2822_inner, don't localize #1322

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
// same as `%a, %d %b %Y %H:%M:%S %z`
{
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
Some(write_rfc2822_inner(w, *d, *t, off, locale))
Some(write_rfc2822(w, crate::NaiveDateTime::new(*d, *t), off))

Check warning on line 398 in src/format/formatting.rs

View check run for this annotation

Codecov / codecov/patch

src/format/formatting.rs#L398

Added line #L398 was not covered by tests
} else {
None
}
Expand Down Expand Up @@ -576,45 +576,35 @@
dt: NaiveDateTime,
off: FixedOffset,
) -> fmt::Result {
write_rfc2822_inner(w, dt.date(), dt.time(), off, default_locale())
}

#[cfg(feature = "alloc")]
/// write datetimes like `Tue, 1 Jul 2003 10:52:37 +0200`, same as `%a, %d %b %Y %H:%M:%S %z`
fn write_rfc2822_inner(
w: &mut impl Write,
d: NaiveDate,
t: NaiveTime,
off: FixedOffset,
locale: Locale,
) -> fmt::Result {
let year = d.year();
let year = dt.year();
// RFC2822 is only defined on years 0 through 9999
if !(0..=9999).contains(&year) {
return Err(fmt::Error);
}

w.write_str(short_weekdays(locale)[d.weekday().num_days_from_sunday() as usize])?;
let english = default_locale();

w.write_str(short_weekdays(english)[dt.weekday().num_days_from_sunday() as usize])?;
w.write_str(", ")?;
let day = d.day();
let day = dt.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_str(short_months(english)[dt.month0() as usize])?;
w.write_char(' ')?;
write_hundreds(w, (year / 100) as u8)?;
write_hundreds(w, (year % 100) as u8)?;
w.write_char(' ')?;

let (hour, min, sec) = t.hms();
let (hour, min, sec) = dt.time().hms();
write_hundreds(w, hour as u8)?;
w.write_char(':')?;
write_hundreds(w, min as u8)?;
w.write_char(':')?;
let sec = sec + t.nanosecond() / 1_000_000_000;
let sec = sec + dt.nanosecond() / 1_000_000_000;
write_hundreds(w, sec as u8)?;
w.write_char(' ')?;
OffsetFormat {
Expand Down
Loading