NodaTime .NET Core 实现中的 BCL DateTimeZoneProvider 在哪里?

Where is the BCL DateTimeZoneProvider in the .NET Core implementation of NodaTime?

我在 ical.net 中使用 NodaTime 进行时区转换,因为它比之前尝试使用 VTIMEZONE 元素处理时间更改和时区转换的实现要好得多。

在幕后,此方法对性能非常重要:它将测试套件运行时间从大约 6 秒减少到大约 2.5 秒。

public static DateTimeZone GetZone(string tzId)
{
    // IANA lookup attempt

    zone = DateTimeZoneProviders.Bcl.GetZoneOrNull(tzId);
    if (zone != null)
    {
        return zone;
    }

    // Serialization lookup attempt
    // Some other tricks to find a reasonable time zone, etc.
}

NodaTime 的 .NET Core 实现没有 Bcl 作为 DateTimeZoneProvider。 (它仍然有 TzdbSerialization。)我在 NodaTime 的源代码中搜索了一下,但我不确定替换是什么,如果有的话。

我们应该使用什么在 NodaTime 的 .NET Core 端口中查找 BCL 时区?

What should we be using for BCL time zone lookups in the .NET Core port of NodaTime?

不幸的是,Noda Time 1.x 支持的 PCL 配置文件中没有很好的 TimeZoneInfo 支持 - 甚至 FindSystemTimeZoneById()Id 属性 未提供。正如评论中所指出的,有令人鼓舞的迹象表明它们可能在 .NET Core 本身中——我需要看看。

您可以使用 TzdbDateTimeZoneSource.WindowsMapping 获得最接近的等效 IANA/TZDB 时区...但理想情况下,如果您可以在整个代码中使用 IANA/TZDB 时区 ID 会更好. (这些对于其他平台也更便携。)

即使 .NET Core 支持 FindSystemTimeZoneById,如果您在 [=37],它也不会提供 Windows 时区=] - 它使用 zoneinfo 文件。因此,如果您需要 Windows 时区可移植性,我认为 WindowsMapping 确实是最佳选择。

更新:再看一遍,我们肯定不能在.NET Core中支持TimeZoneInfo,因为它不公开调整规则:(