From 3e2f151613899586672cc6d4f2246565e44a7bf4 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Tue, 18 Oct 2022 07:53:49 +0100 Subject: [PATCH] remove dyn formatting from timezone (-74/78% on 2822/3339 respectively) --- src/format/mod.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index ed63e4eb7a..39b3db7d82 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -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(()), } }