rbatis / fastdate

fastdate
Apache License 2.0
16 stars 5 forks source link

offset overflow #2

Closed git4unrealnondev closed 2 years ago

git4unrealnondev commented 2 years ago

In datetime.rs the GLOBAL_OFFSET on my machine is set to -18000 When you call: Duration::from_secs(offset as u64) It overflows to the max that u64 can store which causes program to overflow at line 55 causing the program to fault. Duration::from_secs is set to the max that u64 can be. Systemtime looks correct. Not sure why this is happening. Related to fast_log issue that I had opened: https://github.com/rbatis/fast_log/issues/12

Finished dev [unoptimized + debuginfo] target(s) in 0.26s Running target/debug/beans thread 'main' panicked at 'overflow when subtracting duration from instant', library/std/src/time.rs:600:9 stack backtrace: 0: rust_begin_unwind at /rustc/29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6/library/core/src/panicking.rs:142:14 2: core::panicking::panic_display at /rustc/29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6/library/core/src/panicking.rs:72:5 3: core::panicking::panic_str at /rustc/29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6/library/core/src/panicking.rs:56:5 4: core::option::expect_failed at /rustc/29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6/library/core/src/option.rs:1874:5 5: core::option::Option::expect at /rustc/29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6/library/std/src/time.rs:600:9 6: <std::time::SystemTime as core::ops::arith::Sub>::sub at /rustc/29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6/library/std/src/time.rs:600:9 7: fastdate::datetime::DateTime::now at /home/linux/rust/fastdate/src/datetime.rs:55:24 8: beans::main at ./src/main.rs:7:5 9: core::ops::function::FnOnce::call_once at /rustc/29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6/library/core/src/ops/function.rs:248:5 note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

git4unrealnondev commented 2 years ago

Note looks like issue is with timezones and overflow. I set timezone to beijing and it works perfectly fine. I set timezone to chicago and it breaks with overflow.

Program needs support for all UTC timezone i think

zhuxiujia commented 2 years ago

Yes, it's a bug. Has been fixed in a new version. Fastdate does not add time zone information to simplify the time. Instead, it resolves the time zone as it is parsed