Conversation
…; use fromisoformat in DateTimeOffset.parse - Fix date.py parse(): naive datetime strings (no timezone) were incorrectly converted to local time via .astimezone(), giving DateTimeKind.Local instead of DateTimeKind.Unspecified. Now only call .astimezone() when fromisoformat returns an aware datetime. - Improve date_offset.py parse(): try datetime.fromisoformat() first (Python 3.12+) before falling back to dateutil, for better reliability with ISO 8601 strings like '2018-07-02T12:23:45+02:00'. dateutil is still used as a fallback for non-standard formats (e.g. '9/10/2014 1:50:34 PM'). - Add test: DateTime.TryParse with naive string returns DateTimeKind.Unspecified - Add test: DateTimeOffset.TryParse with +02:00 offset returns correct value Fixes #3654 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace dateutil.parser.parse with datetime.fromisoformat + strptime fallback for non-ISO formats. fable-library now has zero runtime dependencies. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
Python Type Checking Results (Pyright)
Excluded files with errors (4 files)These files have known type errors and are excluded from CI. Remove from
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
93 tasks
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.
🤖 This is an automated pull request from Repo Assist.
Closes #3654
Root Cause
Bug 1 —
DateTime.TryParsewith naive strings (date.py)parse()unconditionally calleddatetime.fromisoformat(string).astimezone(). For a naive string like"2018-10-01T11:12:55"(no timezone component),fromisoformatreturns a naivedatetimewithtzinfo=None. Calling.astimezone()on a naive datetime first assumes the input represents local wall-clock time and then converts it to a timezone-aware datetime in the local timezone. This producedDateTimeKind.Localinstead of the correctDateTimeKind.Unspecified.Bug 2 —
DateTimeOffset.parserobustness (date_offset.py)parse()always delegated todateutil.parser.parse, even for ISO 8601 strings that Python 3.12+'s built-indatetime.fromisoformat()handles correctly and without extra dependencies.Fix
date.py— only call.astimezone()whenfromisoformatreturns a timezone-aware datetime:date_offset.py— tryfromisoformatfirst, fall back todateutilfor non-ISO formats:This means
"2018-07-02T12:23:45+02:00"is now parsed via the stdlib (faster, no timezone ambiguity), while"9/10/2014 1:50:34 PM"still goes throughdateutilas before.Tests Added
test DateTime.TryParse preserves Unspecified kind for naive strings— verifies"2018-10-01T11:12:55"givesDateTimeKind.Unspecifiedand the correct date/time valuestest DateTimeOffset.TryParse with timezone offset returns correct value— verifies"2018-07-02T12:23:45+02:00"round-trips correctly toDateTimeOffset(2018, 7, 2, 12, 23, 45, 0, TimeSpan.FromHours(2.))Trade-offs
date_offset.pychange does NOT usedateutilfor ISO strings, butdateutilis still used as a fallback. No existing tests lose coverage.date.pyfix alignsDateTimeKindsemantics with .NET behaviour. Existing tests that only check year/month/day sums are unaffected; tests relying on timezone-aware results for naive strings would need to be fixed (none currently exist).Note
🔒 Integrity filter blocked 131 items
The following items were blocked because they don't meet the GitHub integrity level.
list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".EntryPoint#2366list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".To allow these resources, lower
min-integrityin your GitHub frontmatter: