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

Time Zone IANA Ids to/From Windows Ids conversion APIs #49407

Closed
tarekgh opened this issue Mar 10, 2021 · 7 comments · Fixed by #51093
Closed

Time Zone IANA Ids to/From Windows Ids conversion APIs #49407

tarekgh opened this issue Mar 10, 2021 · 7 comments · Fixed by #51093
Assignees
Labels
api-approved API was approved in API review, it can be implemented area-System.DateTime
Milestone

Comments

@tarekgh
Copy link
Member

tarekgh commented Mar 10, 2021

Background and Motivation

It is planned in 6.0 release to start supporting the IANA time zone Ids on Windows and support Windows Ids on non-Windows platforms (e.g. Linux). That will allow users to use any time zone Id across all platforms without worrying what Id work on what platform.
In addition to that, users need to be able to convert any Windows Id to IANA Id and vice versa. The proposal here is to provide the needed APIs to do that.

As we are using ICU library for supporting IANA Ids and the conversion, we'll be limited to provide this functionality only when running with ICU. i.e. this functionality is not going to be supported in the Globalization Invariant mode nor when enabling NLS mode on Windows. Because of this limitation, the proposed APIs is using TryConvert pattern to allow users check for the conversion failures without throwing any exception.

Proposed API

namespace System
{
    public sealed partial class TimeZoneInfo : IEquatable<TimeZoneInfo?>, ISerializable, IDeserializationCallback
    {
        // Tells if the current TimeZoneInfo Id is Iana Id or not.
        public readonly bool HasIanaId { get; }

        // Try to convert from Iana Id to Windows Id.
        public static bool TryConvertIanaIdToWindowsId(string ianaId, out string windowsId);

        // Try to convert from Windows Id to Iana Id.
        public static bool TryConvertWindowsIdToIanaId(string windowsId, out string ianaId);
        public static bool TryConvertWindowsIdToIanaId(string windowsId, string region, out string ianaId);
    }
}
@tarekgh tarekgh added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 10, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Mar 10, 2021
@tarekgh tarekgh added area-System.Runtime and removed untriaged New issue has not been triaged by the area owner labels Mar 10, 2021
@tarekgh tarekgh self-assigned this Mar 10, 2021
@tarekgh tarekgh added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Mar 10, 2021
@tarekgh tarekgh added this to the 6.0.0 milestone Mar 10, 2021
@danmoseley
Copy link
Member

Cc @mattjohnsonpint

@mattjohnsonpint

This comment has been minimized.

@mattjohnsonpint
Copy link
Contributor

This (along with the other) should help address #18644, and reduce the need for my TimeZoneConverter library. I have functions very similar to these in that library.

@mattjohnsonpint
Copy link
Contributor

mattjohnsonpint commented Mar 10, 2021

To add some supporting details for motivation, there are some scenarios that require such conversion functionality.

  • Processing a time zone received from the browser (via Intl.DateTimeFormat().resolvedOptions().timeZone).
  • Working with Windows time zone IDs stored in a database or file, from a non-Windows machine.
  • Migrating code from older .NET, when it is using Windows IDs and you now want your app or library to be portable.
  • Sending time zones to SQL Server when you need its AT TIME ZONE functionality - since that only works with Windows time zone IDs - even for SQL Server on Linux or Azure. If your .NET app runs on Linux, you will have IANA identifiers and will need to convert.
  • Same as the last item, but interacting with other databases like PostgreSQL or MySQL, which use IANA identifiers. If your .NET app runs on Windows, you will need to convert.
  • Calling any REST API that accepts or returns an IANA identifier when you may be working with Windows identifiers in your application.

I'm sure I'm forgetting several other cases. I believe there was something about wanting support for this in Unity - perhaps something around leaderboard cutoff times and/or multiplayer games with users from various time zones. I can't recall the exact details.

@tarekgh tarekgh added the blocking Marks issues that we want to fast track in order to unblock other important work label Mar 23, 2021
@terrajobst terrajobst added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation blocking Marks issues that we want to fast track in order to unblock other important work labels Mar 26, 2021
@terrajobst
Copy link
Member

terrajobst commented Mar 26, 2021

Video

  • Looks good as proposed but please make sure to properly null-annotate them.
namespace System
{
    public partial class TimeZoneInfo
    {
        public bool HasIanaId { get; }
        public static bool TryConvertIanaIdToWindowsId(string ianaId, out string windowsId);
        public static bool TryConvertWindowsIdToIanaId(string windowsId, out string ianaId);
        public static bool TryConvertWindowsIdToIanaId(string windowsId, string region, out string ianaId);
    }
}

@mattjohnsonpint
Copy link
Contributor

In particular, string? region, where null has the same behavior as the overload without the region.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Apr 12, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Apr 14, 2021
@ghost ghost locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.DateTime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants