-
Notifications
You must be signed in to change notification settings - Fork 544
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
panic with_timezone Jan 1, 1601 00:00 UTC #1364
Comments
Does this work better with #1017? |
Are you suggesting to attempt to patch my system with that PR and attempt again? If you have any notes on doing such a thing, I would be appreciative. |
Yup, I suggest you use a |
I forked chrono, pulled in win_timezone, I tried to make it as hard on myself as possible and modified
I did a ripgrep and ran through all the Cargo.toml that had a chrono dependency, placing the patch section in each. I also added it to the Cargo.toml workspace root file.
I did a My output continues to show a panic with and without the modified patch sections. I may be doing this wrong, let me know.
I can trace through it with a debugger later. cheers. |
Okay. I thought there was a PR to improve on this, maybe it was #997 instead. (Note that you should only need the If it doesn't work with that branch either, I'm happy to review a PR but won't have time to work on this much myself. |
Ok,
I'm still seeing this warning,
I did the cargo update and I still see the warning with this in the lock file.
I didn't feel comfortable that it was overridden well enough on the last attempt so I made the patch section for any Cargo.toml that had chrono as a dep. nushell has a number of crates internally so there is some complication there to ensure that its actually using the code. The attempt I just did using #997 did not change the nushell panic. I'm not sure that the patch is being applied given the lock and warning provided. It would be nice to have a small code sample that panics...maybe I can try and make something. |
I don't want to make another ticket, don't mean to add unrelated comments...but did want to note that the windows tests are not functional for me.
doing gets me closer.
let me know if you have any suggestions on how to get my tests unstuck and I will work on a test to reproduce. Or if you have some other ideas for testing those PRs. thanks. |
You should be using the 0.4.x branch. See if that works better? These tests are executed in CI so stuff should work. |
Thank you, using the proper branch does provide a working test suite on my machine. I created a tests\panics.rs
The above test panics on my machine using: because I added it to panics.rs it was quite easy to I can provide a PR of panics.rs if you'd like. I'm not sure what to do for a change to resolve it. I'm all ears. |
Sorry to say, but cool. This value is seems to be right beyond the range that Windows can represent. Currently I am on Linux and can't test, but would this be Windows way to encode something like While chrono should just not panic, maybe in this case the better solution is for nushell is to detect this as a sentinel value? |
Adjusted for UTC, the time given is 1/1/1601 0:00. Which is exactly the minimum time Windows supports. |
I feel checking sentinel values should be in the library and not in each project that takes on the dependency. |
In any case chrono is not the right place. For chrono there is no reason to treat a timestamp 1601-01-01T00:00:00+00:00 any different from any other timestamp. But for an application that lists files on Windows there may be. But treating it specially is just a suggestion. |
Maybe a new interface with the Option<> which would test for sentinels? Why can't we wrap the call which has the pre-conditions in a windows cfg if inside chrono? I don't think it should panic. Panic wrapping or protecting calls which are known to panic is no ideal. Knowing what the sentinel values are is half the battle. Why shouldn't chrono be responsible for this pre-condition of the windows interface it uses? It would be good to know if Linux has this issue, my guess is no. |
Please think about it some more. Of course I would love to see #1017 make progress so at least chrono is not as prone to panics on Windows as it is now. |
#1017 fails 4 tests for me right now, if I can help there I will too.
if I can help, I will just not sure what to do with #1017 |
Thank you 👍. If you want #1017 is rebased and should be working again. |
Paul, thank you. All tests are passing for #1017. test result: ok. 252 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 16.33s This issue #1364, is still open. I've thought about this quite a bit, making the caller do the checks or wraps is not great. It is a group discussion, I welcome any additional feedback. Thanks for submitting code to reduce the panic in library code! |
So as I understand it this issue happens because we're unable to determine the correct |
@djc Yes, from what I understand we're unable to determine the correct Local offset for dates this far in the past due to the windows API. A new api that does not panic would be nice. |
There is something to be said for protecting the existing interface. If windows api doesn't support dates outside a range, shouldn't chrono ensure this pre-condition is met? Are you looking for me to provide a Local::localize() implementation or might you have time to implement? Where would it live in the codebase? Any notes or words of encouragement towards that improvement are welcome. |
Unfortunately we can't change the existing interface to become fallible because that would require making a semver-incompatible change, which is fairly fraught for something as widely used as chrono. Unfortunately I probably won't have time to implement this, so it would be great if you can give it a shot. It would just live in the https://github.com/chronotope/chrono/blob/0.4.x/src/offset/local/mod.rs#L152 |
@djc I've started working on your review. Sorry again for how much I have been absent. I don't think there is any need to make the API in chrono fallible. It would only be for Windows, and we already have two possible solutions: shift the date by 400 years (not my preference) or work directly with the timezone data from Windows instead of the timezone API. |
No need to be sorry, I haven't exactly been responsive to most of your PRs either...
The latter does sound like it might be more attractive, if it does cover these earlier dates. |
Both of the options require the consumer of the library to do something special on windows? I don't know exactly what it means to work directly with the timezone data vs timezone API. |
No. Shifting by 400 years (a leap year cycle) is the solution proposed in #997. And #1017 is the solution to use |
naive\mod.rs defines MIN/MAX for NaiveDateTime and it also has the UNIX_EPOCH in there. 1600 doesn't have a definition as #997 mentions. nevevss mentions there's a docstring somewhere in SYSTEMTIME that designates a valid value. From testing it seems that dates greater than 1601 work. 1601 panics. So >1600 is not a good test since it has to be >1601. We use 1600 a few places.
We use 1601 one place in a comment.
that comment is from:
In my testing greater than 1601 works, the comment seems to indicate 1601 should work but does not for me. https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime Should the system_time_from_naive_date_time be checking for validity and falliable. In other words, the caller of the with_timezone should ensure validity of the date before calling with_timezone. @pitdicker I spent some time tonight trying to understand how to implement either proposed change and I'm not sure how to proceed. I'm still a little lost on what to do. lmk if you have any additional thoughts, I will continue looking at it. |
Hm, as far as the Windows API is concerned it should only be a issue for times on 1601-01-01. From 1601-01-02 onward it should work. The only issue with the 1st is that the time offset could cause the year to rollback to 1600 and therefore I think using |
@ChrisDenton thanks. The panic tests work as you indicated. Which means we can't just check the year for >1600 and we have to address the 01/01 special. BTW what does OP in 'in the OP' mean? I'm still not sure of a solution without some additional direction, I'm talking to ChatGPT. Are we still talking about a new interface
this is GPT filling in junk. Actually, nushell created the Option<> interface and points to 4.19 as the source. I'd ask why calculating the UNIX_EPOCH makes sense at all and a general function to test for SYSTEMTIME validity be called instead.
the -sec, and 1_000_000_000 constants make me sad. Are we just missing a validity check for those of us on a win32 machine?
chrono has a
Don't know anything about this MaybeUninit which might provide a means to do this check idk. SAFETY comments aside, I think this call to SystemTimeTzSpecificLocalTime should be protected with a validity check. |
Sorry, it's shorthand for "Opening Post". I just meant to say that the specific problem that started this thread is the 1/1/1601 UTC problem. When getting a time from a file, the current way chrono is use means we start with a UTC, |
I submitted a patch to nushell to filter out the unsafe values. This ticket may well be closed -- maybe live as long as the above PR?, I'm unsure how to fix the api in general to protect against these panics. |
#1017 is the preferred solution |
I'm trying to do an ls \.\pipe in nushell which causes a panic.
The ls \.\pipe lists the pipes on windows and according to powershell that date is 12/31/1600 7:00PM.
nushell/nushell#10464
I have some details in my PR which sets and unsets the panic handler around chrono to handle the panic thrown from Chrono.
nushell/nushell#10558
Is there a way to make another interface/function which does not unwrap panic when called?
wrapping chrono in panic hooks to handle panic'ing unwraps on Jan 1, 1601 00:00 UTC and other reasons unknown is not ideal and I would love to have a better solution.
I'm not sure what chrono should tell me the timezone is in 1600, but I would prefer it not be via a panic.
The text was updated successfully, but these errors were encountered: