Fix: DateTime::to_timezone corrupting non-whole-hour offsets by storing leftover seconds in tz_minute (closes #158)

This commit is contained in:
Maurus Decimus
2026-08-20 15:10:50 +02:00
parent b4366b7537
commit 5528d5b49f
3 changed files with 32 additions and 2 deletions
+4
View File
@@ -1,3 +1,7 @@
mail-parser 0.11.7
================================
- Fix: `DateTime::to_timezone` corrupting non-whole-hour offsets by storing leftover seconds in `tz_minute` (#158)
mail-parser 0.11.6
================================
- Fix: Missing whitespace between a quoted name and a following encoded word (#150)
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "mail-parser"
description = "Fast and robust e-mail parsing library for Rust"
version = "0.11.6"
version = "0.11.7"
edition = "2024"
authors = [ "Stalwart Labs <hello@stalw.art>"]
license = "Apache-2.0 OR MIT"
+27 -1
View File
@@ -258,7 +258,7 @@ impl DateTime {
dt.tz_before_gmt = tz < 0;
let tz = tz.abs();
dt.tz_hour = (tz / 3600) as u8;
dt.tz_minute = (tz % 3600) as u8;
dt.tz_minute = ((tz % 3600) / 60) as u8;
dt
}
}
@@ -539,4 +539,30 @@ mod tests {
}
}
}
#[test]
fn datetime_to_timezone() {
let dt = DateTime::parse_rfc3339("2021-01-01T00:00:00Z").unwrap();
for (tz, expected) in [
(0i64, "2021-01-01T00:00:00Z"),
(3600, "2021-01-01T01:00:00+01:00"),
(-3600, "2020-12-31T23:00:00-01:00"),
(19800, "2021-01-01T05:30:00+05:30"),
(-12600, "2020-12-31T20:30:00-03:30"),
(20700, "2021-01-01T05:45:00+05:45"),
(16200, "2021-01-01T04:30:00+04:30"),
(34200, "2021-01-01T09:30:00+09:30"),
(-45900, "2020-12-31T11:15:00-12:45"),
] {
let converted = dt.to_timezone(tz);
assert_eq!(converted.to_rfc3339(), expected, "failed for tz {tz}");
assert!(converted.is_valid(), "invalid datetime for tz {tz}");
assert_eq!(
converted.to_timestamp(),
dt.to_timestamp(),
"roundtrip failed for tz {tz}"
);
}
}
}