-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Make DateTimeOffset a readonly struct #19552
Conversation
| { | ||
| _offsetMinutes = ValidateOffset(Offset); | ||
| _dateTime = ValidateDate(ClockDateTime, Offset); | ||
| ValidateOffset(Offset); |
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.
Throws if
new TimeSpan(0, _offsetMinutes, 0).Ticks % TimeSpan.TicksPerMinute != 0and returns
new TimeSpan(0, _offsetMinutes, 0).Ticks / TimeSpan.TicksPerMinuteSo if the _offsetMinutes is valid it doesn't change it, and if invalid it throws (are other checks); so the assignment is redundant (also prevents it being readonly)
| _offsetMinutes = ValidateOffset(Offset); | ||
| _dateTime = ValidateDate(ClockDateTime, Offset); | ||
| ValidateOffset(Offset); | ||
| ValidateDate(ClockDateTime, Offset); |
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.
Offset => new TimeSpan(0, _offsetMinutes, 0);
ClockDateTime => new DateTime((_dateTime + Offset).Ticks, DateTimeKind.Unspecified)
long utcTicks = ClockDateTime.Ticks - Offset.Ticks;
return new DateTime(utcTicks, DateTimeKind.Unspecified);Again if the validation passes, it will just return the original value; so the assignment is redundant (also prevents it being readonly)
jkotas
left a 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.
Thanks
|
(We will also need matching change in reference assemblies in CoreFX.) |
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
On it |
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
16 byte struct; currently problematic to use with
inAlso when
DateTimeOffsetis used as areadonlyfield/cc @jkotas @stephentoub