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
Changes requested by review
  • Loading branch information
mkhamoyan committed Sep 6, 2023
commit 4d9b1f6adb364c448b423309794f332798f8f8fe
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public sealed partial class TimeZoneInfo
{
private const string InvariantUtcStandardDisplayName = "Coordinated Universal Time";
private const string FallbackCultureName = "en-US";
#if !TARGET_MACCATALYST && TARGET_IOS && TARGET_TVOS
private const string GmtId = "GMT";

// Some time zones may give better display names using their location names rather than their generic name.
Expand All @@ -22,6 +23,7 @@ public sealed partial class TimeZoneInfo
"Pacific/Apia", // Prefer "Samoa Time" over "Apia Time"
"Pacific/Pitcairn" // Prefer "Pitcairn Islands Time" over "Pitcairn Time"
};
#endif

private static CultureInfo? _uiCulture;

Expand Down Expand Up @@ -159,15 +161,13 @@ private static void GetFullValueForDisplayNameField(string timeZoneId, TimeSpan
string baseOffsetText = string.Create(null, stackalloc char[128], $"(UTC{(baseUtcOffset >= TimeSpan.Zero ? '+' : '-')}{baseUtcOffset:hh\\:mm})");

#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
if (GlobalizationMode.Hybrid)
{
string? timeZoneName = null;
GetDisplayName(timeZoneId, Interop.Globalization.TimeZoneDisplayNameType.TimeZoneName, uiCulture.Name, ref timeZoneName);
// For this target, be consistent with other time zone display names that use the ID.
displayName = $"{baseOffsetText} {timeZoneName}";
return;
}
#endif
Debug.Assert(GlobalizationMode.Hybrid);
string? timeZoneName = null;
GetDisplayName(timeZoneId, Interop.Globalization.TimeZoneDisplayNameType.TimeZoneName, uiCulture.Name, ref timeZoneName);
// For this target, be consistent with other time zone display names that use the ID.
displayName = $"{baseOffsetText} {timeZoneName}";
return;
#else
// There are a few different ways we might show the display name depending on the data.
// The algorithm used below should avoid duplicating the same words while still achieving the
// goal of providing a unique, discoverable, and intuitive name.
Expand Down Expand Up @@ -267,6 +267,7 @@ private static void GetFullValueForDisplayNameField(string timeZoneId, TimeSpan

displayName = $"{baseOffsetText} {genericName} ({exemplarCityName})";
}
#endif
}

// Helper function that gets an exmplar city name either from ICU or from the IANA time zone ID itself
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include "pal_errors_internal.h"
#include "pal_locale_internal.h"
#include "pal_icushim_internal.h"
#include "pal_timeZoneInfo.h"
#import <Foundation/Foundation.h>

mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -30,7 +30,7 @@ int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeN
else
{
NSLocale *currentLocale;
if(localeName == NULL || lNameLength == 0)
if (localeName == NULL || lNameLength == 0)
{
currentLocale = [NSLocale systemLocale];
}
Expand Down Expand Up @@ -69,6 +69,8 @@ int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeN
{
dstCodepoint = [timeZoneName characterAtIndex: index];
Append(result, dstIdx, resultLength, dstCodepoint, resultCode);
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
if (resultCode != Success)
return resultCode;
index++;
}
dstCodepoint = '\0';
Expand Down