Skip to content

Commit

Permalink
Inline write_rfc2822_inner, don't localize
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 27, 2023
1 parent e28f2af commit 22846c9
Showing 1 changed file with 9 additions and 19 deletions.
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 @@ fn format_inner(
// 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))
} else {
None
}
Expand Down Expand Up @@ -576,45 +576,35 @@ pub(crate) fn write_rfc2822(
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

0 comments on commit 22846c9

Please sign in to comment.