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

[iOS][non-icu] HybridGlobalization implement timezoneinfo functions #91458

Merged
merged 15 commits into from
Sep 7, 2023
Prev Previous commit
Next Next commit
Fix wasm build
  • Loading branch information
mkhamoyan committed Sep 1, 2023
commit b44508f68667803fc065e43d99da23b1ff278cce
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<ILLinkSharedDirectory>$(MSBuildThisFileDirectory)ILLink\</ILLinkSharedDirectory>
<IsBigEndian Condition="'$(Platform)' == 's390x'">true</IsBigEndian>
<Is64Bit Condition="'$(Platform)' == 'arm64' or '$(Platform)' == 'x64' or '$(Platform)' == 's390x' or '$(Platform)' == 'loongarch64' or '$(Platform)' == 'ppc64le' or '$(Platform)' == 'riscv64'">true</Is64Bit>
<UseMinimalGlobalizationData Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">true</UseMinimalGlobalizationData>
<UseMinimalGlobalizationData Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">true</UseMinimalGlobalizationData>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(IsBigEndian)' == 'true'">$(DefineConstants);BIGENDIAN</DefineConstants>
Expand Down Expand Up @@ -1272,7 +1272,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZone.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.AdjustmentRule.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.FullGlobalizationData.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.FullGlobalizationData.cs" Condition="'$(UseMinimalGlobalizationData)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.StringSerializer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.TransitionTime.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneNotFoundException.cs" />
Expand Down Expand Up @@ -1357,10 +1357,10 @@
<Compile Include="$(CommonPath)Interop\Interop.ResultCode.cs">
<Link>Common\Interop\Interop.ResultCode.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Interop.TimeZoneDisplayNameType.cs">
<Compile Include="$(CommonPath)Interop\Interop.TimeZoneDisplayNameType.cs" Condition="'$(UseMinimalGlobalizationData)' != 'true'">
<Link>Common\Interop\Interop.TimeZoneDisplayNameType.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Interop.TimeZoneInfo.cs">
<Compile Include="$(CommonPath)Interop\Interop.TimeZoneInfo.cs" Condition="'$(UseMinimalGlobalizationData)' != 'true'">
<Link>Common\Interop\Interop.TimeZoneInfo.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Interop.TimeZoneInfo.iOS.cs" Condition="'$(IsiOSLike)' == 'true'">
Expand Down Expand Up @@ -2476,7 +2476,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.Android.cs" Condition="'$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.NonAndroid.cs" Condition="'$(TargetsAndroid)' != 'true' and '$(TargetsLinuxBionic)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.FullGlobalizationData.Unix.cs" />

</ItemGroup>
<ItemGroup Condition="('$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(IsOSXLike)' != 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStatus.SetTimes.OtherUnix.cs" />
Expand Down Expand Up @@ -2504,6 +2504,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.iOS.cs" Condition="'$(IsiOSLike)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.Unix.cs" Condition="'$(IsOSXLike)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.SunOS.cs" Condition="'$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.FullGlobalizationData.Unix.cs" Condition="'$(UseMinimalGlobalizationData)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Unix.cs" />
</ItemGroup>
Expand All @@ -2519,6 +2520,9 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Browser.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\RuntimeInformation.Browser.cs" />
</ItemGroup>
<ItemGroup Condition="'$(UseMinimalGlobalizationData)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.MinimalGlobalizationData.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsOSXLike)' == 'true'">
<Compile Include="$(CommonPath)Interop\OSX\Interop.libobjc.cs">
<Link>Common\Interop\OSX\Interop.libobjc.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public sealed partial class TimeZoneInfo
private static string GetUtcStandardDisplayName()
{
System.Diagnostics.Debug.Write("TimeZoneInfo.GetUtcStandardDisplayName is called.\n");
#if TARGET_BROWSER || TARGET_WASI
// For this target, be consistent with other time zone display names that use an abbreviation.
return "UTC";
#elif TARGET_IOS || TARGET_TVOS
#if TARGET_IOS || TARGET_TVOS
if (!GlobalizationMode.Hybrid)
{
// For this target, be consistent with other time zone display names that use an abbreviation.
Expand All @@ -59,10 +56,7 @@ private static string GetUtcStandardDisplayName()
// Helper function to get the full display name for the UTC static time zone instance
private static string GetUtcFullDisplayName(string timeZoneId, string standardDisplayName)
{
#if TARGET_BROWSER || TARGET_WASI
// For this target, be consistent with other time zone display names that use the ID.
return $"(UTC) {timeZoneId}";
#elif TARGET_IOS || TARGET_TVOS
#if TARGET_IOS || TARGET_TVOS
if (!GlobalizationMode.Hybrid)
{
// For this target, be consistent with other time zone display names that use the ID.
Expand Down Expand Up @@ -116,7 +110,7 @@ private static unsafe void GetDisplayName(string timeZoneId, Interop.Globalizati
{
fixed (char* bufferPtr = buffer)
{
#if TARGET_IOS || TARGET_TVOS || TARGET_BROWSER || TARGET_WASI
#if TARGET_IOS || TARGET_TVOS
if (GlobalizationMode.Hybrid)
return Interop.Globalization.GetTimeZoneDisplayNameNative(locale, locale.Length, id, id.Length, type, bufferPtr, buffer.Length);
#endif
Expand All @@ -136,7 +130,7 @@ private static unsafe void GetDisplayName(string timeZoneId, Interop.Globalizati
{
fixed (char* bufferPtr = buffer)
{
#if TARGET_IOS || TARGET_TVOS || TARGET_BROWSER || TARGET_WASI
#if TARGET_IOS || TARGET_TVOS
if (GlobalizationMode.Hybrid)
return Interop.Globalization.GetTimeZoneDisplayNameNative(locale, locale.Length, id, id.Length, type, bufferPtr, buffer.Length);
#endif
Expand Down Expand Up @@ -285,7 +279,7 @@ private static string GetExemplarCityName(string timeZoneId, string uiCultureNam
// Helper function that returns an alternative ID using ICU data. Used primarily for converting from Windows IDs.
private static unsafe string? GetAlternativeId(string id, out bool idIsIana)
{
#if TARGET_IOS || TARGET_TVOS || TARGET_BROWSER || TARGET_WASI
#if TARGET_IOS || TARGET_TVOS
// No alternative IDs in this target.
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
idIsIana = false;
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System
{
public sealed partial class TimeZoneInfo
{
#pragma warning disable IDE0060
static partial void GetFullValueForDisplayNameField(string timeZoneId, TimeSpan baseUtcOffset, ref string? displayName);

static partial void GetStandardDisplayName(string timeZoneId, ref string? displayName);

static partial void GetDaylightDisplayName(string timeZoneId, ref string? displayName);

private static string GetUtcStandardDisplayName()
{
// For this target, be consistent with other time zone display names that use an abbreviation.
return "UTC";
}

private static string GetUtcFullDisplayName(string timeZoneId, string standardDisplayName)
{
// For this target, be consistent with other time zone display names that use the ID.
return $"(UTC) {timeZoneId}";
}

private static string? GetAlternativeId(string id, out bool idIsIana)
{
// No alternative IDs in this target.
idIsIana = false;
return null;
}

private static unsafe bool TryConvertIanaIdToWindowsId(string ianaId, bool allocate, out string? windowsId)
{
windowsId = null;
return false;
}

private static unsafe bool TryConvertWindowsIdToIanaId(string windowsId, string? region, bool allocate, out string? ianaId)
{
ianaId = null;
return false;
}
#pragma warning restore IDE0060
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (GlobalizationMode.Invariant)
return displayName;

#if TARGET_IOS || TARGET_TVOS || TARGET_BROWSER || TARGET_WASI
#if TARGET_IOS || TARGET_TVOS
return displayName;
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't we skipping the new native code completely if we return before calling GetFullValueForDisplayNameField here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use NSTimeZone.name for hybrid mode

GetFullValueForDisplayNameField(Id, BaseUtcOffset, ref displayName);
Expand All @@ -248,7 +248,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (GlobalizationMode.Invariant)
return standardDisplayName;

#if TARGET_IOS || TARGET_TVOS || TARGET_BROWSER || TARGET_WASI
#if TARGET_IOS || TARGET_TVOS
if (!GlobalizationMode.Hybrid)
return standardDisplayName;
#endif
Expand All @@ -266,7 +266,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (GlobalizationMode.Invariant)
return daylightDisplayName;

#if TARGET_IOS || TARGET_TVOS || TARGET_BROWSER || TARGET_WASI
#if TARGET_IOS || TARGET_TVOS
if (!GlobalizationMode.Hybrid)
return daylightDisplayName;
#endif
Expand Down