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 failure on maccatalyst
  • Loading branch information
mkhamoyan committed Sep 5, 2023
commit 88088d8a95a283583c464ab2bd2b650bcac089cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed partial class TimeZoneInfo
// Helper function to get the standard display name for the UTC static time zone instance
private static string GetUtcStandardDisplayName()
{
#if TARGET_IOS || TARGET_TVOS
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
if (!GlobalizationMode.Hybrid)
{
// For this target, be consistent with other time zone display names that use an abbreviation.
Expand All @@ -55,7 +55,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_IOS || TARGET_TVOS
#if TARGET_MACCATALYST || 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 @@ -109,7 +109,7 @@ private static unsafe void GetDisplayName(string timeZoneId, Interop.Globalizati
{
fixed (char* bufferPtr = buffer)
{
#if TARGET_IOS || TARGET_TVOS
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
if (GlobalizationMode.Hybrid)
return Interop.Globalization.GetTimeZoneDisplayNameNative(locale, locale.Length, id, id.Length, type, bufferPtr, buffer.Length);
#endif
Expand All @@ -129,7 +129,7 @@ private static unsafe void GetDisplayName(string timeZoneId, Interop.Globalizati
{
fixed (char* bufferPtr = buffer)
{
#if TARGET_IOS || TARGET_TVOS
#if TARGET_MACCATALYST || 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 @@ -278,7 +278,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
#if TARGET_MACCATALYST || 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
Expand Up @@ -9,7 +9,7 @@ public sealed partial class TimeZoneInfo
{
private static unsafe bool TryConvertIanaIdToWindowsId(string ianaId, bool allocate, out string? windowsId)
{
#if TARGET_IOS || TARGET_TVOS
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
windowsId = null;
return false;
#else
Expand Down Expand Up @@ -37,7 +37,7 @@ ianaId is null ||

private static unsafe bool TryConvertWindowsIdToIanaId(string windowsId, string? region, bool allocate, out string? ianaId)
{
#if TARGET_IOS || TARGET_TVOS
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
ianaId = null;
return false;
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ private static bool TryGetLocalTzFile([NotNullWhen(true)] out byte[]? rawData, [
#pragma warning disable IDE0074 // Use compound assignment
if (tzVariable == null)
{
#if TARGET_IOS || TARGET_TVOS
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
tzVariable = Interop.Sys.GetDefaultTimeZone();
#elif TARGET_WASI || TARGET_BROWSER
if (UseEmbeddedTzDatabase)
Expand Down
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
#if TARGET_MACCATALYST || 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 @@ -249,7 +249,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (GlobalizationMode.Invariant)
return standardDisplayName;

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

#if TARGET_IOS || TARGET_TVOS
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
if (!GlobalizationMode.Hybrid)
return daylightDisplayName;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static void Names()
// Name abbreviations, if available, are used instead
public static IEnumerable<object[]> Platform_TimeZoneNamesTestData()
{
if (PlatformDetection.IsBrowser || (!PlatformDetection.IsHybridGlobalizationOnOSX && (PlatformDetection.IsiOS || PlatformDetection.IstvOS)))
if (PlatformDetection.IsBrowser || (!PlatformDetection.IsHybridGlobalizationOnOSX && (PlatformDetection.IsMacCatalyst || PlatformDetection.IsiOS || PlatformDetection.IstvOS)))
return new TheoryData<TimeZoneInfo, string, string, string, string>
{
{ TimeZoneInfo.FindSystemTimeZoneById(s_strPacific), "(UTC-08:00) America/Los_Angeles", null, "PST", "PDT" },
Expand All @@ -100,7 +100,7 @@ public static IEnumerable<object[]> Platform_TimeZoneNamesTestData()
{ s_NewfoundlandTz, "(UTC-03:30) America/St_Johns", null, "NST", "NDT" },
{ s_catamarcaTz, "(UTC-03:00) America/Argentina/Catamarca", null, "-03", "-02" }
};
else if(PlatformDetection.IsHybridGlobalizationOnOSX && (PlatformDetection.IsiOS || PlatformDetection.IstvOS))
else if (PlatformDetection.IsHybridGlobalizationOnOSX && (PlatformDetection.IsMacCatalyst || PlatformDetection.IsiOS || PlatformDetection.IstvOS))
return new TheoryData<TimeZoneInfo, string, string, string, string>
{
{ TimeZoneInfo.FindSystemTimeZoneById(s_strPacific), "(UTC-08:00) America/Los_Angeles", null, "Pacific Standard Time", "Pacific Daylight Time" },
Expand Down