3 ms·
I'm not sure I agree. When I convert fields to DateTime, I remove the unit suffix from the name. The DateTime is supposed to be an implementation-agnostic point
by kqr 5y ago
I'm not sure I agree. When I convert fields to DateTime, I remove the unit suffix from the name. The DateTime is supposed to be an implementation-agnostic point in time. It shouldn't come with any units, and nor should they be exposed by the internal implementation.
The factory method used to convert e.g. Unix timestamps to DateTimes, now that should indicate whether we're talking seconds or milliseconds since epoch, for example, and when the epoch really was.
- gregmac 5y agoThey do: .ToUnixTimeSeconds() .ToUnixTimeMilliseconds() DateTimeOffset.FromUnixTimeSeconds(Int64) DateTimeOffset.FromUnixTimeMilliseconds(Int64) https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tounixtimeseconds?view=net-6.0 https://docs.microsoft.com/en-us/dotnet/api/system.datetimeo... https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset.fromunixtimeseconds?view=net-6.0 https://docs.microsoft.com/en-us/dotnet/api/system.datetimeo...
- stevesimmons 5y agoHow does the C# DateTime type distinguish between dates and a point in time whose time just happens to be midnight? Much of the C# code I've seen uses names like start_date with no indication of whether it really is a date (with no timezone), a date (in one particular timezone), or a datetime where the time is significant. I'm certainly not a C# developer, though my quick reading of the docs suggests that the DateOnly type was only introduced recently in .NET6.
- Sharparam 5y agoYeah, before the new DateOnly (and TimeOnly) types, there was no built-in way in C# to specify a plain date. NodaTime[1] (a popular third-party library for datetime operations) did have such types though. [1]: https://nodatime.org/ https://nodatime.org/