From e73d4204ffa820aa1842d991354943b49e431c5f Mon Sep 17 00:00:00 2001 From: zxj Date: Thu, 29 Aug 2024 11:41:25 +0800 Subject: [PATCH] fix display bug --- Cargo.toml | 2 +- src/datetime.rs | 10 +++++----- tests/datetime.rs | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fc5efdf..d719491 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fastdate" -version = "0.3.32" +version = "0.3.33" edition = "2021" description = "Rust fast date carte" readme = "Readme.md" diff --git a/src/datetime.rs b/src/datetime.rs index 90ef02a..c05ba50 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -22,7 +22,7 @@ pub fn offset_sec() -> i32 { } /// set GLOBAL_OFFSET -pub fn set_offset_sec(sec:i32) { +pub fn set_offset_sec(sec: i32) { GLOBAL_OFFSET.store(sec, Ordering::SeqCst); } @@ -508,14 +508,14 @@ impl DateTime { len += 1; buf[len] = b'0' + (h as u8 % 10); len += 1; - buf[len] = b':' + (m as u8 / 10); + buf[len] = b':'; len += 1; buf[len] = b'0' + (m as u8 / 10); len += 1; buf[len] = b'0' + (m as u8 % 10); len += 1; if s != 0 { - buf[len] = b':' + (s as u8 / 10); + buf[len] = b':'; len += 1; buf[len] = b'0' + (s as u8 / 10); len += 1; @@ -529,14 +529,14 @@ impl DateTime { len += 1; buf[len] = b'0' + (-h as u8 % 10); len += 1; - buf[len] = b':' + (-m as u8 / 10); + buf[len] = b':'; len += 1; buf[len] = b'0' + (-m as u8 / 10); len += 1; buf[len] = b'0' + (-m as u8 % 10); len += 1; if s != 0 { - buf[len] = b':' + (-s as u8 / 10); + buf[len] = b':'; len += 1; buf[len] = b'0' + (-s as u8 / 10); len += 1; diff --git a/tests/datetime.rs b/tests/datetime.rs index d4ad984..77cdaf9 100644 --- a/tests/datetime.rs +++ b/tests/datetime.rs @@ -587,6 +587,16 @@ fn test_ser_date() { assert_eq!(js, "\"2023-10-13T16:57:41.123926+08:00\""); } + +#[test] +fn test_offset_href(){ + //5*3600 + 3600/2 + let mut date = DateTime::from_str("2023-10-13 16:57:41.123926+08:00").unwrap(); + date = date.set_offset(5*3600 + 3600/2); + let js = serde_json::to_string(&date).unwrap(); + assert_eq!(js, "\"2023-10-13T14:27:41.123926+05:30\""); +} + #[test] fn test_de_date() { let date = DateTime::from_str("2023-10-13 16:57:41.123926+08:00").unwrap();