From 695e71b6274cf4387a1f2f39dbcfc56b5ae7f561 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sun, 5 Jan 2020 22:28:07 +0100 Subject: [PATCH] common: Implement Time::fmt_date(). --- src/common/time.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/common/time.rs b/src/common/time.rs index e11dea4..de41e35 100644 --- a/src/common/time.rs +++ b/src/common/time.rs @@ -24,7 +24,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -use fmt::fmt_u32_pad; +use fmt::{fmt_u32, fmt_u32_pad}; pub struct Time { seconds: i32, @@ -118,6 +118,20 @@ impl Time { } } + pub fn fmt_date(&self, s: &mut [u8]) { + let mut offset = 0; + + offset += fmt_u32(&mut s[offset..], self.year as u32 + 1900); + s[offset] = b'-'; + offset += 1; + + offset += fmt_u32_pad(&mut s[offset..], self.month as u32 + 1, 2, b'0'); + s[offset] = b'-'; + offset += 1; + + fmt_u32_pad(&mut s[offset..], self.day as u32, 2, b'0'); + } + pub fn fmt_time(&self, s: &mut [u8]) { let mut offset = 0; -- 2.30.2