Skip to content

Commit

Permalink
remove dyn formatting from timezone (-74/78% on 2822/3339 respectively)
Browse files Browse the repository at this point in the history
  • Loading branch information
conradludgate committed Oct 26, 2022
1 parent 923421f commit e42fc89
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/format/mod.rs
Expand Up @@ -736,26 +736,28 @@ fn write_local_minus_utc(
colon_type: Colons,
) -> fmt::Result {
let off = off.local_minus_utc();
if !allow_zulu || off != 0 {
let (sign, off) = if off < 0 { ('-', -off) } else { ('+', off) };
if allow_zulu && off == 0 {
result.push('Z');
return Ok(());
}
let (sign, off) = if off < 0 { ('-', -off) } else { ('+', off) };
result.push(sign);

match colon_type {
Colons::None => {
write!(result, "{}{:02}{:02}", sign, off / 3600, off / 60 % 60)
}
Colons::Single => {
write!(result, "{}{:02}:{:02}", sign, off / 3600, off / 60 % 60)
}
Colons::Double => {
write!(result, "{}{:02}:{:02}:{:02}", sign, off / 3600, off / 60 % 60, off % 60)
}
Colons::Triple => {
write!(result, "{}{:02}", sign, off / 3600)
}
write_hundreds(result, (off / 3600) as u8)?;

match colon_type {
Colons::None => write_hundreds(result, (off / 60 % 60) as u8),
Colons::Single => {
result.push(':');
write_hundreds(result, (off / 60 % 60) as u8)
}
} else {
result.push('Z');
Ok(())
Colons::Double => {
result.push(':');
write_hundreds(result, (off / 60 % 60) as u8)?;
result.push(':');
write_hundreds(result, (off % 60) as u8)
}
Colons::Triple => Ok(()),
}
}

Expand Down

0 comments on commit e42fc89

Please sign in to comment.