update human-date-parser to 3.0#15426
Merged
fdncred merged 3 commits intonushell:mainfrom Apr 1, 2025
Merged
Conversation
132ikl
reviewed
Mar 27, 2025
Comment on lines
+307
to
+335
| let local_offset = *Local::now().offset(); | ||
| let datetime = match local_offset.from_local_datetime(&date) { | ||
| chrono::LocalResult::Single(dt) => dt, | ||
| chrono::LocalResult::Ambiguous(_, _) => { | ||
| return Value::error( | ||
| ShellError::DatetimeParseError { | ||
| msg: "Ambiguous datetime".to_string(), | ||
| span, | ||
| }, | ||
| span, | ||
| ); | ||
| } | ||
| chrono::LocalResult::None => { | ||
| return Value::error( | ||
| ShellError::DatetimeParseError { | ||
| msg: "Invalid datetime".to_string(), | ||
| span, | ||
| }, | ||
| span, | ||
| ); | ||
| } | ||
| }; | ||
| let dt_fixed = TimeZone::from_local_datetime( | ||
| &local_offset, | ||
| &datetime.naive_local(), | ||
| ) | ||
| .single() | ||
| .unwrap_or_default(); | ||
| return Value::date(dt_fixed, span); |
Member
There was a problem hiding this comment.
could you explain what exactly this is doing, was this prompted by a change in human-date-parser 3.0?
Contributor
Author
There was a problem hiding this comment.
Sure.
- Yes, the api to human-date-parser changed so the way we call it has to change.
- The key to this match here is, if it's a date use local time + provided date, if it's a time, use local date + provided time, if it's a datetime use that.
- The match returns a NativeDate, NativeTime, or NativeDateTime. None have a tz. So, the idea is to use the local tz. That's what local_offset is about.
- Then local_offset.from_local_datetime() returns LocalResult which is what that match is about.
- Then I cleanup some left over code, oops. Let me fix that now. Thanks for making me explain it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
There's been much debate about whether to keep human-date-parser in
into datetime. We saw recently that a new version of the crate was released that addressed some of our concerns. This PR is to make it easier to test those fixes.User-Facing Changes
Tests + Formatting
After Submitting