Skip to content

Commit 2a4f187

Browse files
authored
Fix timezone-dependent chrono tests with fixed timestamps (#528)
Replace dynamic timestamp comparisons with fixed timestamps in chrono tests to ensure consistent behavior across all timezone environments. Fixes #151 Replaces #150
2 parents 7195282 + f293c5c commit 2a4f187

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

crates/duckdb/src/types/chrono.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,10 @@ mod test {
325325
#[test]
326326
fn test_naive_date_time_param() -> Result<()> {
327327
let db = checked_memory_handle()?;
328+
let fixed_time = NaiveDateTime::parse_from_str("2023-01-01 12:00:00", "%Y-%m-%d %H:%M:%S").unwrap();
328329
let result: Result<bool> = db.query_row(
329-
"SELECT 1 WHERE ?::TIMESTAMP BETWEEN (now() AT TIME ZONE 'UTC' - INTERVAL '1 minute') AND (now() AT TIME ZONE 'UTC' + INTERVAL '1 minute')",
330-
[Utc::now().naive_utc()],
330+
"SELECT 1 WHERE ?::TIMESTAMP BETWEEN (TIMESTAMP '2023-01-01 11:59:00') AND (TIMESTAMP '2023-01-01 12:01:00')",
331+
[fixed_time],
331332
|r| r.get(0),
332333
);
333334
assert!(result.is_ok());
@@ -337,13 +338,12 @@ mod test {
337338
#[test]
338339
fn test_date_time_param() -> Result<()> {
339340
let db = checked_memory_handle()?;
340-
// TODO(wangfenjin): why need 2 params?
341+
let fixed_time = Utc.with_ymd_and_hms(2023, 1, 1, 12, 0, 0).unwrap();
341342
let result: Result<bool> = db.query_row(
342-
"SELECT 1 WHERE ?::TIMESTAMP BETWEEN (now() AT TIME ZONE 'UTC' - INTERVAL '1 minute') AND (now() AT TIME ZONE 'UTC' + INTERVAL '1 minute')",
343-
[Utc::now()],
343+
"SELECT 1 WHERE ?::TIMESTAMPTZ BETWEEN (TIMESTAMPTZ '2023-01-01 11:59:00+00:00') AND (TIMESTAMPTZ '2023-01-01 12:01:00+00:00')",
344+
[fixed_time],
344345
|r| r.get(0),
345346
);
346-
println!("{result:?}");
347347
assert!(result.is_ok());
348348
Ok(())
349349
}

0 commit comments

Comments
 (0)