-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix invalid datetimeoffset parsing #87801
Merged
tarekgh
merged 2 commits into
dotnet:main
from
Maximys:bugfix/51740-invalid-datetimeoffset-parsing
Jun 24, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericstj (or somebody else from area-System.DateTime), pay attention on this line, please. I think, expected value should be represented by DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan), but max value of millisecond is 999, that's why I could not use this constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarekgh , thanks, but next code result is false:
because dt.Ticks is 637547798573076420 and dt2.Ticks is 637547798573076423 (last digit is different), that's why I had post my previous comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note I used
"2021-04-23T13:04:17,307642000+02:00"
and not"2021-04-23T13:04:17.307642270+02:00"
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Maximys any news?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarekgh , yes, you are right, with 6 significant digits (I mean "307642" without "270") test will be successful, but inside bug we have "2021-04-23T13:04:17,307642270+02:00". As you can see, count of significant digits of "2021-04-23T13:04:17,307642270+02:00" is 8 ("30764227"), which add 3 to last digit of Ticks ("0.xxxx227" rounded to "0.xxxx3") and I think, that we should not use good data to test case just for pass it.
If you want to know my opinion, I think we should change type of "microsecond" argument from Int32 to float and apply range 0<=microsecond<1000. Then we can pass 642.3 to it and my test will be pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we cannot do that for compatibility reasons. We never change APIs signature after we ship.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new DateTimeOffset(2021, 4, 23, 13, 4, 17, TimeSpan.FromHours(2)).AddTicks(3076423)
would have been another option, easier to visually verify as equivalent to2021-04-23T13:04:17,307642300+02:00
. Not worth changing now, though.