-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Developers can benefit from enhanced Date and Time types and Timezone support #45318
Comments
@tarekgh this is great, I retitled it in user-focused terms as it's a user story |
Added to #44314 so it appears in https://themesof.net/?q=is:open%20kinds:teub |
A shout from the Java side: please have a look at the work done in JSR-310 to introduce modern date/time abstractions in Java 8: https://www.threeten.org/ Java has had a long and painful history with time handling (e.g. Also, having a standard |
@shtratos we are aware of Joda time and there is already the Noda time library implementing that. The |
@tarekgh - I think the call there is (once again) to implement a full date/time library in core, not to limit things to just the basic Outside of restating my own desires in that direction, getting new types into a new |
@Clockwork-Muse When we reach the design phase, we'll discuss the options having the new types in its own library or be inside System.Private.Corlib. Also, the design should discuss the options having the new types in a new namespace. I think this all valid points to explore. I agree the new types shouldn't have any dependencies on DateTime but may consider have implicit/explicit conversion for interop usages. that would be part of the design discussion too. Thanks for the feedback. |
Just to add some thoughts. (All of the below is IMHO, of course):
|
I'll also add two more examples:
|
I do agree we could add a |
FYI, here's an example where having a |
I would also like to add that a very common use case is to collect an end-user's time zone from their browser in a web application using the JavaScript: Today, one has two choices to handle this server-side in ASP.Net running on Windows:
Going forward, I would like to see a way to do this directly in ASP.Net without requiring libraries. In my opinion, an end-to-end example in ASP.Net of picking a time zone by starting with the browser's default time zone and using it in C# code would be very useful to end users. |
I led the design work for the IANA-timezone-aware type called ZonedDateTime in JavaScript Temporal. One learning from this design is that types like .Net's So one suggestion I'd have is to add a new type (or expand functionality of existing types) to include a type that will automatically adjust the offset according to the rules of the time zone as the underlying date/time changes. The data model of such a type would be [UTC value, IANA time zone]. Another learning is that naming types "Date" and "Time" can potentially be problematic because so many platforms use those names to mean types that include more than just a plain date or plain time. In JavaScript we're going to call those types Feel free to reach out if you have more questions about Temporal. I worked on the .NET 1.0 API long ago when I worked at MSFT so I have some .NET context too, although not as much recent knowledge as @mj1856. |
Thanks for your feedback @justingrant! I tend to agree with most of your points. Though keep in mind that the challenge we face with .NET is that unlike Java and JavaScript, we aren't (IMHO) in a great position to overhaul the entire date/time type system. The existing structures That's been the driving principle behind the need to add
There is also a concern about how to handle existing behaviors. Are any breaking changes to be tolerated? I could see the following breaking changes being reasonable and useful in light of those two new types. (I'll use
|
With regard to a |
Also, In regard to the first two items on the features list at the top of this issue - I'd actually be in favor of a whole new time zone type, or overhauling the |
What exactly the breaking changes you are suggesting in TimeZoneInfo? |
.... another breaking change to consider (that has almost no chance of happening) - remove Personally I feel some programmers may be lead astray by That aside, all this is why I've been wanting to just go the Java route and add a whole new date/time API. |
@Clockwork-Muse - I don't believe removing |
@tarekgh - Let me get back to you on the |
Note that the current
The main reason to add a
Agree! I actually tried to recommend those names for that reason in Temporal, but that didn't fly there. ;-) Although does Visual Studio IntelliSense still limit itself to "starts with" matching? Or does it now act like VS Code where "match inside" also works? If the latter then the placement of the "Date" / "Time" part is less critical than the past. That said, it's helpful for other places where alphabetic sorting is used, e.g. documentation, so I'd still recommend XxxxOnly vs. PrefixXxxx. |
Thinking a bit more about the suggestion of including an |
Please keep discussing the issue on #36617 and not here. the reason is #36617 is talking in general about mockability and also protentional breaking changes for removing the ISystemClock types from all other extension libraries. This is not about just adding a simple interface. The design review video on the issue is discussing all of that. |
All items in this issue already taken care of. |
Date and Time features proposal
This issue is capturing the Date and Time candidate tasks for .NET 6.0 release. It lists every proposed feature and the reason for having it in the candidate list.
Features List
Features Details
Time zone ids
Currently when running on Windows, .NET read the time zone data from Windows registry which include the time zone Windows Ids e.g.
Standard Pacific Time
. Trying to create a TimeZoneInfo using IANA time zone Ids on Windows will fail and will get exception. The reason of that is .NET don't have any source of getting such Ids and map it to Windows Ids.The same problem occur on Linux/OSX too. On Linux/OSX we read the time zone data for the installed time zone package which include only IANA time zone Ids e.g.
America/Los_Angeles
. Trying to create a TimeZoneInfo using Windows Ids will fail and throw exception.It has been requested multiple times to support IANA Ids on Windows and support Windows Ids on Linux/OSX. #14929 show the demand on this feature and capture the discussions and the demand on it. We delayed the support of this feature because we didn't have a good source of the time zone data which can help converting the IANA Ids to Windows Ids and vice versa. Also, .NET avoided carrying the data because servicing such data will be big deal especially time zone data is very dynamic and constantly change.
We have been recommending using the TimeZoneConverter library as a workaround which helped a lot to unblock user's scenarios. The issue is some users cannot take dependency on none core packages and want to have this support natively in the .NET.
Fortunately, in .NET 5.0 we have started to use ICU library for the globalization support. ICU has time zone APIs which can help in converting Windows Ids to IANA Ids and vice versa. .NET can take advantage of ICU to implement such feature.
ICU provide the TimeZone class which provide the methods TimeZone::getWindowsID and TimeZone::getIDForWindowsID can be used to implement the feature. There are some catches though which we need to consider as part of the feature design:
Adjustment Rules Enhancement
When we ported the TimeZoneInfo code to Linux and exposed the APIs that handle the time zone adjustment rules, there was some limitations. The original design of the AdjustmentRule was based on how the time zone data format we read from Windows Registry while the data we read from Linux is very different. Although we tried to make it work with this limitation, it still not returning a prefect results in all cases. This issue is reported many times in issues like #44475, #20626, and #20624. The proposal here is do the following:
Date & Time types
.NET expose DateTime and DateTimeOffset for handling date and time. It has been requested multiple time to expose Date only and Time only structs. There are many scenarios users need to handle Dates without caring about time at all. And scenarios need to handle time without caring about Date. Users today try to work around that by using DateTime or DateTimeOffset but users need to truncate the parts they don’t need and want to ensure the remaining values is not affected. This is error prone as DateTime and DateTimeOffset also carry some time zone related things and it is not meant handle absolute date and time.
There is detailed discussions about such requested in the reported issues #14744, #1740 and #14089. Initially we have suggested to expose these features outside the core as a NuGet package. This is implemented in corefxlab https://github.com/dotnet/corefxlab/tree/master/src/System.Time. Users still requesting this functionality to be in core and they wanted to avoid dependencies on third party libraries and make sense such functionality be in the core. The corefxlab implementation is a good start as it has the full exposure and working functionality. Need just some polishing to be moved to core. Some points we need to consider when moving it to core:
Time
ok to use but it could be many users define their own Time type. When exposing Time that can conflict with user types. This is a generic issue that usually occur when using names that can conflict with user defined types (Span is a good example of that). It is important to have the right name in core though for discoverability purpose.Date
is more problematic name as Visual Basic exposed aliased type with that name. This can be issue there and we need to evaluate if we can easily do something to help with that conflicts or just try to find another name.Miscellaneous Fixes
We have some other issues and features related to dates and time. Investigating and resolving these issues would help the users in general.
The text was updated successfully, but these errors were encountered: