-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SystemTimeToTzSpecificLocalTime failed with: The parameter is incorrect. (os error 87) #651
Comments
use std::{io, mem};
use winapi::{shared::minwindef::*, um::timezoneapi::*};
fn main() {
// works - 132790361186042732
// fails - 147221225472
let t = 147221225472 as u64;
let ft = FILETIME {
dwLowDateTime: t as DWORD,
dwHighDateTime: (t >> 32) as DWORD,
};
unsafe {
let mut utc = mem::zeroed();
let mut local = mem::zeroed();
FileTimeToSystemTime(&ft, &mut utc);
dbg!(&utc.wYear); // 1601
dbg!(&utc.wMonth); // 1
dbg!(&utc.wDayOfWeek); // 1 (Monday)
dbg!(&utc.wDay); // 1
dbg!(&utc.wHour);
dbg!(&utc.wMinute);
dbg!(&utc.wSecond);
dbg!(&utc.wMilliseconds);
SystemTimeToTzSpecificLocalTime(0 as *const _, &mut utc, &mut local); // returns 0 (failure)
dbg!(io::Error::last_os_error()); // InvalidInput
}
} Those debug statements tell you that the SystemTime is January 1, 1601. And while that seems totally ridiculous, it should be a valid date according to Microsoft documentation. Despite this, passing that value to [src\main.rs:31] io::Error::last_os_error() = Os {
code: 87,
kind: InvalidInput,
message: "The parameter is incorrect.",
} |
This seems to be an issue with something lower level having to do with Windows, so I'm going to close this. We opened an issue in the official |
Actually, I'm reopening this since based on the feedback from that issue it looks like the problem might be more in chrono's domain. |
I'm unable to test on Windows myself. I'd be happy to review any code changes that are supported with documentation and/or explanation why they improve the current situation, but I probably won't be able to work on this proactively. Let me know if you need any guidance on how to fix chrono to support this scenario better. |
@annmarie-switzer should have the fix for this. Unfortunately, I don't have the code and also am unable to test on Windows. |
Just adding some additional info: We (Nushell) recently got a bug report where this panic was occurring when the user ran The culprit ended up being a file named |
While #1150 is a duplicate of this issue, it becomes a bit more specific on what to fix. |
We're getting a panic from chrono here when run on a Windows 2012 server:
We debugged the
SystemTime
we were getting and it was:A normal
intervals
value (e.g.132790361186042732
) is much larger.I'm assuming there's something about this unusually short
SystemTime
that's causing chrono to panic.The text was updated successfully, but these errors were encountered: