-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Conversation
@jkotas this is just porting what we have done in the full framework. Also, I have created a commit for corert we can use when we are mirroring this change there tarekgh/corert@f79f7c8 could you please take a look at both and let me know if you have any comment? I have tested this on coreclr, corert and ProjectN native and Win32. I did the testing on Windows version which support leaps seconds with inserting some fake leap seconds to the system. |
Is there going to be a matching PR with the tests in CoreFX? |
We already have tests for DateTime/DateTimeOffset exercise Now, UtcNow. Writing any test specific for testing with leap seconds will not have any effect because we'll have to run on a machine support leap seconds (i.e. RS5) and the system will have a leaps seconds which we don't have any so far. This will be interesting more when we get in the future a leap seconds. |
There are two separate problems:
|
I'll write a test for that but I'll not expect this test will fail now and the possibility to fail in the future will be low. I understand your point and would be good to have it to catch if we would have a problem. |
@@ -432,6 +432,7 @@ | |||
</ItemGroup> | |||
<ItemGroup Condition="'$(TargetsWindows)' == 'true'"> | |||
<Compile Include="$(BclSourcesRoot)\System\DateTime.Windows.cs" /> | |||
<Compile Include="shared/Interop/Windows/NtDll/Interop.NtQuerySystemInformation.cs" /> |
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.
This should be in the project in the shared partition
|
||
[MethodImplAttribute(MethodImplOptions.InternalCall)] | ||
internal static extern bool SystemTimeToSystemFileTime(ref FullSystemTime time, ref long fileTime); | ||
internal static extern bool SystemTimeToSystemFileTime(ref Interop.Kernel32.SYSTEMTIME time, out long fileTime); |
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.
The first argument can be in Interop.Kernel32.SYSTEMTIME
|
||
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] | ||
internal static extern bool IsLeapSecondsSupportedSystem(); | ||
internal static extern bool ValidateSystemTime(ref Interop.Kernel32.SYSTEMTIME time, bool localTime); |
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.
The first argument can be in
FullSystemTime time = new FullSystemTime(); | ||
if (SystemFileTimeToSystemTime(fileTime, ref time)) | ||
FullSystemTime time; | ||
if (SystemFileTimeToSystemTime(fileTime, out time)) |
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.
Nit: if (SystemFileTimeToSystemTime(fileTime, out FullSystemTime time))
FullSystemTime time = new FullSystemTime(ticks); | ||
if (SystemTimeToSystemFileTime(ref time, ref fileTime)) | ||
if (SystemTimeToSystemFileTime(ref time.systemTime, out fileTime)) |
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.
Nit: if (SystemTimeToSystemFileTime(ref time.systemTime, out long fileTime))
internal static extern bool ValidateSystemTime(ref Interop.Kernel32.SYSTEMTIME time, bool localTime); | ||
|
||
[MethodImplAttribute(MethodImplOptions.InternalCall)] | ||
internal static extern bool SystemFileTimeToSystemTime(long fileTime, out FullSystemTime time); |
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.
Is there a reason why we call some of these things SystemFileTime
? There is SYSTEMTIME
and FILETIME
today, but there is no SystemFileTime today.
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.
I was trying to have it clear FILETIME is always a system file time. if you think this is confusing, I can change it.
{ | ||
FCALL_CONTRACT; | ||
|
||
if (::SystemTimeToFileTime(time, (LPFILETIME) pFileTime)) |
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.
This does not need if - can just return the value returned by SystemTimeToFileTime.
BOOL ret = ::SystemTimeToFileTime(...
FC_RETURN_BOOL(ret);
return new DateTime(universalTicks, DateTimeKind.Utc); | ||
} | ||
|
||
public long ToFileTimeUtc() { |
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.
Nit: {
should be on a new line
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.
Those was a copy and paste from other file. I'll fix them.
} | ||
|
||
ticks -= FileTimeOffset; | ||
if (ticks < 0) { |
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.
Same
hundredNanoSecond = 0; | ||
} | ||
|
||
internal Interop.Kernel32.SYSTEMTIME systemTime; |
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.
The coding convention is to place the fields first.
} | ||
} | ||
|
||
public static DateTime FromFileTimeUtc(long fileTime) |
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.
The only difference between Windows and Unix versions of FromFileTimeUtc and ToFileTimeUtc is the callout to the special method method for leap seconds. Should we have keep it in the shared and have a dummy method on Unix?
Also, it may be better to call InternalFromFileTime / InternalToFileTime something like FromFileTimeUtcLeapSecondsAware / ToFileTimeUtcLeapSecondAware
.
Do you have the number for performance hit that the methods like I think we had it in one of the offline conversations ... it would be useful to have the number on here too. |
Looks good to me otherwise |
I don't have the exact numbers here and also I am using a VM for my leap seconds testing. but I have tested it and we always reporting the time on the same milliseconds boundary. Here example for what I was doing: SYSTEMTIME st = new SYSTEMTIME();
GetSystemTime(ref st);
DateTime dt = DateTime.UtcNow;
Console.WriteLine($"<{st.wHour:D2}:{st.wMinute:D2}:{st.wSecond:D2}.{st.wMillisecond:D2}> .... [{dt.Hour:D2}:{dt.Minute:D2}:{dt.Second:D2}.{dt.Millisecond:D2}]"); Note that we still reporting the precise time as we used to do even in leap seconds system. the only extra perf is just the time we use till we return. I can do the measurements later to get the exact numbers. note that we already have a perf tests for this too. anyway, let me know if you want to wait not merging the change till we do that or we case merge and do the measurements later. if we want to wait, I'll hold this changes till next year. |
I do not think you need to block on this. |
test Windows_NT x64 Checked Innerloop Build and Test (Jit - TieredCompilation=0) |
thanks @jkotas for your review and comments. I will wait preparing the changes for corert too and test it so we'll be ready when we merge. I'll let you know when I have it ready to take a quick look there too. |
here is the delta changes in corert repo too tarekgh/corert@b503742 i have tested it with PN too. after reviewing the delta, I'll squash moth commits in corert to one so it will be easy to use. |
Thanks a lot @jkotas for your review. I have updated the corert too and squashed the commits into one commit tarekgh/corert@389615a |
* Leap Seconds Support * Address Feedback * More feedback addressing Signed-off-by: dotnet-bot <[email protected]>
I added a comment too on corert change tarekgh/corert@389615a#r31609074 may be we need to apply. |
* Leap Seconds Support * Address Feedback * More feedback addressing Signed-off-by: dotnet-bot <[email protected]>
@Anipik I am noticing there is no corert mirroring PR opened for this one. Is it expected? |
@tarekgh it is expected in the sense that there can be only one open mirror pr in a repo at any time. |
Thanks @Anipik |
* Leap Seconds Support * Address Feedback * More feedback addressing Signed-off-by: dotnet-bot <[email protected]>
* Leap Seconds Support * Address Feedback * More feedback addressing Signed-off-by: dotnet-bot <[email protected]>
* Leap Seconds Support * Address Feedback * More feedback addressing
* Leap Seconds Support * Address Feedback * More feedback addressing Signed-off-by: dotnet-bot <[email protected]>
* Leap Seconds Support * Address Feedback * More feedback addressing Commit migrated from dotnet/coreclr@98e4995
Port the leap seconds changes done in the full framework to net core.