Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@benaadams
Copy link
Member

@benaadams benaadams commented Aug 19, 2018

16 byte struct; currently problematic to use with in

Also when DateTimeOffset is used as a readonly field

System\DateTimeOffset.cs(47):        public static readonly DateTimeOffset MinValue = new DateTimeOffset(DateTime.MinTicks, TimeSpan.Zero);
System\DateTimeOffset.cs(48):        public static readonly DateTimeOffset MaxValue = new DateTimeOffset(DateTime.MaxTicks, TimeSpan.Zero);
System\DateTimeOffset.cs(49):        public static readonly DateTimeOffset UnixEpoch = new DateTimeOffset(DateTime.UnixEpochTicks, TimeSpan.Zero);

/cc @jkotas @stephentoub

{
_offsetMinutes = ValidateOffset(Offset);
_dateTime = ValidateDate(ClockDateTime, Offset);
ValidateOffset(Offset);
Copy link
Member Author

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 != 0

and returns

new TimeSpan(0, _offsetMinutes, 0).Ticks / TimeSpan.TicksPerMinute

So 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);
Copy link
Member Author

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)

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas jkotas merged commit 9499b08 into dotnet:master Aug 20, 2018
@jkotas
Copy link
Member

jkotas commented Aug 20, 2018

(We will also need matching change in reference assemblies in CoreFX.)

dotnet-maestro-bot pushed a commit to dotnet-maestro-bot/corefx that referenced this pull request Aug 20, 2018
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
dotnet-maestro-bot pushed a commit to dotnet-maestro-bot/corert that referenced this pull request Aug 20, 2018
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jkotas pushed a commit to dotnet/corefx that referenced this pull request Aug 20, 2018
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
@benaadams
Copy link
Member Author

(We will also need matching change in reference assemblies in CoreFX.)

On it

@benaadams benaadams deleted the readonly-DateTimeOffset branch August 20, 2018 18:11
jkotas pushed a commit to dotnet/corert that referenced this pull request Aug 21, 2018
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants