This is an automated email from the ASF dual-hosted git repository.
xushiyan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hudi-rs.git
The following commit(s) were added to refs/heads/main by this push:
new fb3b798 fix: make local timezone test more robust (#308)
fb3b798 is described below
commit fb3b798eed3997f608d957b6d3f1fa0daa391b78
Author: Shiyan Xu <[email protected]>
AuthorDate: Sat Mar 15 14:28:24 2025 -0500
fix: make local timezone test more robust (#308)
---
Cargo.toml | 2 +-
crates/core/src/timeline/instant.rs | 19 ++++++++++++++-----
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 95cacb2..7affc9d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -63,7 +63,7 @@ serde_json = { version = "1.0" }
# "stdlib"
thiserror = { version = "2.0.11" }
bytes = { version = "1" }
-chrono = { version = "0.4" }
+chrono = { version = "=0.4.39" }
lazy_static = { version = "1.5.0" }
log = { version = "0.4" }
paste = { version = "1.0.15" }
diff --git a/crates/core/src/timeline/instant.rs
b/crates/core/src/timeline/instant.rs
index e715b6a..ff9ef46 100644
--- a/crates/core/src/timeline/instant.rs
+++ b/crates/core/src/timeline/instant.rs
@@ -180,7 +180,7 @@ impl Instant {
TimelineTimezoneValue::UTC =>
Ok(DateTime::from_naive_utc_and_offset(naive_dt, Utc)),
TimelineTimezoneValue::Local => Ok(Local
.from_local_datetime(&naive_dt)
- .earliest()
+ .single()
.ok_or_else(|| CoreError::Timeline("Invalid local
datetime".to_string()))?
.to_utc()),
}
@@ -358,13 +358,22 @@ mod tests {
#[test]
fn test_create_instant_using_local_timezone() {
+ // Set a fixed timezone for consistent testing
+ let original_tz = std::env::var("TZ").ok();
+ std::env::set_var("TZ", "Etc/GMT+5"); // UTC-5 fixed timezone with no
DST
+
let file_name = "20240103153000.commit";
let instant_local =
Instant::try_from_file_name_and_timezone(file_name, "local").unwrap();
let instant_utc = Instant::try_from_file_name_and_timezone(file_name,
"utc").unwrap();
let offset_seconds = (instant_local.epoch_millis -
instant_utc.epoch_millis) / 1000;
- assert_eq!(
- offset_seconds,
- Local::now().offset().utc_minus_local() as i64
- );
+
+ // Expected: In UTC+5, the offset should be exactly 5 hours
+ assert_eq!(offset_seconds, 5 * 3600);
+
+ // Restore original TZ
+ match original_tz {
+ Some(tz) => std::env::set_var("TZ", tz),
+ None => std::env::remove_var("TZ"),
+ }
}
}