Skip to content
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

Make ToFileTime understand DateTime.MinValue #6288

Closed
magol opened this issue Jul 8, 2016 · 4 comments
Closed

Make ToFileTime understand DateTime.MinValue #6288

magol opened this issue Jul 8, 2016 · 4 comments

Comments

@magol
Copy link

magol commented Jul 8, 2016

DateTime.ToFileTime

When you want to denote an unknown date in .NET, you normally use DateTime.MinValue or default(DateTime).
The equality for a FileTime is 0 (See WIN32_FILE_ATTRIBUTE_DATA structure)

But, if you try to use DateTime.ToFileTime(DateTime.MinValue) you get an ArgumentOutOfRangeException.

My suggestion is to make DateTime.ToFileTime to returns 0 if it gets DateTime.MinValue as input.

DateTime.FromFileTimes

Even in the opposite situation, when you want to use DateTime.FromFileTime, have an issue as I see it. If the FileTime is 0, it returns new DateTime(1601, 1, 1, 1, 0, 0). It is not entirely wrong, and is manageable. But I think it is semantically wrong when it returns something that looks like a specific date. I suggest that it returns DateTime.MinValue if it gets 0 as input.
That is an braking change, but I see it as acceptable when I do not think that this special case is not so common

@adityamandaleeka
Copy link
Member

@tarekgh @stephentoub

@tarekgh
Copy link
Member

tarekgh commented Jul 13, 2016

When you want to denote an unknown date in .NET, you normally use DateTime.MinValue or default(DateTime).

this is not really true. DateTime.MinValue is known date and cannot be used as unknown value especially if you are going to use it in subsequent operations like ToFileTime for instance.
if we return 0 in ToFileTime this means we are return date equivalent to 1/1/1601 and not equivalent to 1/1/1

looks to me you need to use Nullable type and not DateTime.MinValue
https://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx

@magol
Copy link
Author

magol commented Jul 15, 2016

It is true that DateTime.MinValue is a known date.
But it is also true that DateTime.MinValue == default(DateTime) so also an uninitialized DateTime have this value.
Purely pragmatic one can consider it as an uninitialized value. But you're right, it must be correct.

@tarekgh
Copy link
Member

tarekgh commented Jul 15, 2016

@magol default(somthing) doesn't mean this is uninitialized. it means it is initialized with the default value. when you do something like

int i = default(int); is equivalent to int i= 0; // this is initialization

for reference types too, string s = default(string); is equivalent to string s = null; // this is still initialization even we assign it to null.

this is why I recommended to use Nullable to differentiate between the initialized and uninitialized DateTiem.

I am closing the issue but please reply back or reopen it if you have any more feedback. Thanks.

@tarekgh tarekgh closed this as completed Jul 15, 2016
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants