From: Tilman Sauerbeck Date: Sun, 5 Jan 2020 21:28:07 +0000 (+0100) Subject: common: Implement Time::fmt_date(). X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=695e71b6274cf4387a1f2f39dbcfc56b5ae7f561;p=gps-watch.git common: Implement Time::fmt_date(). --- 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;