Skip to content

Commit

Permalink
fix display bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Aug 29, 2024
1 parent c03de0b commit e73d420
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e73d420

Please sign in to comment.