Skip to content

Commit a0fc08e

Browse files
Improve time zone display names on Unix (#48931)
1 parent aab9aa6 commit a0fc08e

File tree

11 files changed

+758
-120
lines changed

11 files changed

+758
-120
lines changed

src/libraries/Common/src/Interop/Interop.TimeZoneDisplayNameType.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ internal enum TimeZoneDisplayNameType
1111
Generic = 0,
1212
Standard = 1,
1313
DaylightSavings = 2,
14+
GenericLocation = 3,
15+
ExemplarCity = 4,
1416
}
1517
}
1618
}

src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,33 @@
5858
// (U_ICU_VERSION_MAJOR_NUM < 52)
5959
// The following APIs are not supported in the ICU versions less than 52. We need to define them manually.
6060
// We have to do runtime check before using the pointers to these APIs. That is why these are listed in the FOR_ALL_OPTIONAL_ICU_FUNCTIONS list.
61-
U_CAPI int32_t U_EXPORT2 ucal_getWindowsTimeZoneID(const UChar* id, int32_t len,UChar* winid, int32_t winidCapacity, UErrorCode* status);
6261
U_CAPI int32_t U_EXPORT2 ucal_getTimeZoneIDForWindowsID(const UChar* winid, int32_t len, const char* region, UChar* id, int32_t idCapacity, UErrorCode* status);
62+
U_CAPI int32_t U_EXPORT2 ucal_getWindowsTimeZoneID(const UChar* id, int32_t len, UChar* winid, int32_t winidCapacity, UErrorCode* status);
6363
#endif
6464

6565
// List of all functions from the ICU libraries that are used in the System.Globalization.Native.so
6666
#define FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \
6767
PER_FUNCTION_BLOCK(u_charsToUChars, libicuuc, true) \
6868
PER_FUNCTION_BLOCK(u_getVersion, libicuuc, true) \
69+
PER_FUNCTION_BLOCK(u_strcmp, libicuuc, true) \
70+
PER_FUNCTION_BLOCK(u_strcpy, libicuuc, true) \
6971
PER_FUNCTION_BLOCK(u_strlen, libicuuc, true) \
7072
PER_FUNCTION_BLOCK(u_strncpy, libicuuc, true) \
7173
PER_FUNCTION_BLOCK(u_tolower, libicuuc, true) \
7274
PER_FUNCTION_BLOCK(u_toupper, libicuuc, true) \
75+
PER_FUNCTION_BLOCK(u_uastrcpy, libicuuc, true) \
7376
PER_FUNCTION_BLOCK(ucal_add, libicui18n, true) \
7477
PER_FUNCTION_BLOCK(ucal_close, libicui18n, true) \
7578
PER_FUNCTION_BLOCK(ucal_get, libicui18n, true) \
7679
PER_FUNCTION_BLOCK(ucal_getAttribute, libicui18n, true) \
7780
PER_FUNCTION_BLOCK(ucal_getKeywordValuesForLocale, libicui18n, true) \
7881
PER_FUNCTION_BLOCK(ucal_getLimit, libicui18n, true) \
82+
PER_FUNCTION_BLOCK(ucal_getNow, libicui18n, true) \
7983
PER_FUNCTION_BLOCK(ucal_getTimeZoneDisplayName, libicui18n, true) \
8084
PER_FUNCTION_BLOCK(ucal_open, libicui18n, true) \
85+
PER_FUNCTION_BLOCK(ucal_openTimeZoneIDEnumeration, libicui18n, true) \
8186
PER_FUNCTION_BLOCK(ucal_set, libicui18n, true) \
87+
PER_FUNCTION_BLOCK(ucal_setMillis, libicui18n, true) \
8288
PER_FUNCTION_BLOCK(ucol_close, libicui18n, true) \
8389
PER_FUNCTION_BLOCK(ucol_closeElements, libicui18n, true) \
8490
PER_FUNCTION_BLOCK(ucol_getOffset, libicui18n, true) \
@@ -96,6 +102,7 @@ U_CAPI int32_t U_EXPORT2 ucal_getTimeZoneIDForWindowsID(const UChar* winid, int3
96102
PER_FUNCTION_BLOCK(ucol_strcoll, libicui18n, true) \
97103
PER_FUNCTION_BLOCK(udat_close, libicui18n, true) \
98104
PER_FUNCTION_BLOCK(udat_countSymbols, libicui18n, true) \
105+
PER_FUNCTION_BLOCK(udat_format, libicui18n, true) \
99106
PER_FUNCTION_BLOCK(udat_getSymbols, libicui18n, true) \
100107
PER_FUNCTION_BLOCK(udat_open, libicui18n, true) \
101108
PER_FUNCTION_BLOCK(udat_setCalendar, libicui18n, true) \
@@ -202,21 +209,27 @@ FOR_ALL_ICU_FUNCTIONS
202209
// to the functions of the selected version of ICU in the initialization.
203210
#define u_charsToUChars(...) u_charsToUChars_ptr(__VA_ARGS__)
204211
#define u_getVersion(...) u_getVersion_ptr(__VA_ARGS__)
212+
#define u_strcmp(...) u_strcmp_ptr(__VA_ARGS__)
213+
#define u_strcpy(...) u_strcpy_ptr(__VA_ARGS__)
205214
#define u_strlen(...) u_strlen_ptr(__VA_ARGS__)
206215
#define u_strncpy(...) u_strncpy_ptr(__VA_ARGS__)
207216
#define u_tolower(...) u_tolower_ptr(__VA_ARGS__)
208217
#define u_toupper(...) u_toupper_ptr(__VA_ARGS__)
218+
#define u_uastrcpy(...) u_uastrcpy_ptr(__VA_ARGS__)
209219
#define ucal_add(...) ucal_add_ptr(__VA_ARGS__)
210220
#define ucal_close(...) ucal_close_ptr(__VA_ARGS__)
211221
#define ucal_get(...) ucal_get_ptr(__VA_ARGS__)
212222
#define ucal_getAttribute(...) ucal_getAttribute_ptr(__VA_ARGS__)
213223
#define ucal_getKeywordValuesForLocale(...) ucal_getKeywordValuesForLocale_ptr(__VA_ARGS__)
214224
#define ucal_getLimit(...) ucal_getLimit_ptr(__VA_ARGS__)
225+
#define ucal_getNow(...) ucal_getNow_ptr(__VA_ARGS__)
215226
#define ucal_getTimeZoneDisplayName(...) ucal_getTimeZoneDisplayName_ptr(__VA_ARGS__)
216227
#define ucal_getTimeZoneIDForWindowsID(...) ucal_getTimeZoneIDForWindowsID_ptr(__VA_ARGS__)
217228
#define ucal_getWindowsTimeZoneID(...) ucal_getWindowsTimeZoneID_ptr(__VA_ARGS__)
218229
#define ucal_open(...) ucal_open_ptr(__VA_ARGS__)
230+
#define ucal_openTimeZoneIDEnumeration(...) ucal_openTimeZoneIDEnumeration_ptr(__VA_ARGS__)
219231
#define ucal_set(...) ucal_set_ptr(__VA_ARGS__)
232+
#define ucal_setMillis(...) ucal_setMillis_ptr(__VA_ARGS__)
220233
#define ucol_close(...) ucol_close_ptr(__VA_ARGS__)
221234
#define ucol_closeElements(...) ucol_closeElements_ptr(__VA_ARGS__)
222235
#define ucol_getOffset(...) ucol_getOffset_ptr(__VA_ARGS__)
@@ -241,6 +254,7 @@ FOR_ALL_ICU_FUNCTIONS
241254
#define ucurr_getName(...) ucurr_getName_ptr(__VA_ARGS__)
242255
#define udat_close(...) udat_close_ptr(__VA_ARGS__)
243256
#define udat_countSymbols(...) udat_countSymbols_ptr(__VA_ARGS__)
257+
#define udat_format(...) udat_format_ptr(__VA_ARGS__)
244258
#define udat_getSymbols(...) udat_getSymbols_ptr(__VA_ARGS__)
245259
#define udat_open(...) udat_open_ptr(__VA_ARGS__)
246260
#define udat_setCalendar(...) udat_setCalendar_ptr(__VA_ARGS__)

src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal_android.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef struct UBreakIterator UBreakIterator;
2525
typedef int8_t UBool;
2626
typedef uint16_t UChar;
2727
typedef int32_t UChar32;
28+
typedef double UDate;
2829
typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH];
2930

3031
typedef void* UNumberFormat;
@@ -369,6 +370,12 @@ typedef enum UCollationResult {
369370
UCOL_LESS = -1
370371
} UCollationResult;
371372

373+
typedef enum USystemTimeZoneType {
374+
UCAL_ZONE_TYPE_ANY,
375+
UCAL_ZONE_TYPE_CANONICAL,
376+
UCAL_ZONE_TYPE_CANONICAL_LOCATION
377+
} USystemTimeZoneType;
378+
372379
enum {
373380
UIDNA_ERROR_EMPTY_LABEL = 1,
374381
UIDNA_ERROR_LABEL_TOO_LONG = 2,
@@ -419,25 +426,36 @@ typedef struct UIDNAInfo {
419426
int32_t reservedI3;
420427
} UIDNAInfo;
421428

429+
typedef struct UFieldPosition {
430+
int32_t field;
431+
int32_t beginIndex;
432+
int32_t endIndex;
433+
} UFieldPosition;
422434

423435

424436
void u_charsToUChars(const char * cs, UChar * us, int32_t length);
425437
void u_getVersion(UVersionInfo versionArray);
426438
int32_t u_strlen(const UChar * s);
439+
int32_t u_strcmp(const UChar * s1, const UChar * s2);
440+
UChar * u_strcpy(UChar * dst, const UChar * src);
427441
UChar * u_strncpy(UChar * dst, const UChar * src, int32_t n);
428442
UChar32 u_tolower(UChar32 c);
429443
UChar32 u_toupper(UChar32 c);
444+
UChar* u_uastrcpy(UChar * dst, const char * src);
430445
void ucal_add(UCalendar * cal, UCalendarDateFields field, int32_t amount, UErrorCode * status);
431446
void ucal_close(UCalendar * cal);
432447
int32_t ucal_get(const UCalendar * cal, UCalendarDateFields field, UErrorCode * status);
433448
int32_t ucal_getAttribute(const UCalendar * cal, UCalendarAttribute attr);
434449
UEnumeration * ucal_getKeywordValuesForLocale(const char * key, const char * locale, UBool commonlyUsed, UErrorCode * status);
435450
int32_t ucal_getLimit(const UCalendar * cal, UCalendarDateFields field, UCalendarLimitType type, UErrorCode * status);
451+
UDate ucal_getNow(void);
436452
int32_t ucal_getTimeZoneDisplayName(const UCalendar * cal, UCalendarDisplayNameType type, const char * locale, UChar * result, int32_t resultLength, UErrorCode * status);
437-
UCalendar * ucal_open(const UChar * zoneID, int32_t len, const char * locale, UCalendarType type, UErrorCode * status);
438-
void ucal_set(UCalendar * cal, UCalendarDateFields field, int32_t value);
439453
int32_t ucal_getTimeZoneIDForWindowsID(const UChar * winid, int32_t len, const char * region, UChar * id, int32_t idCapacity, UErrorCode * status);
440454
int32_t ucal_getWindowsTimeZoneID(const UChar * id, int32_t len, UChar * winid, int32_t winidCapacity, UErrorCode * status);
455+
UCalendar * ucal_open(const UChar * zoneID, int32_t len, const char * locale, UCalendarType type, UErrorCode * status);
456+
UEnumeration * ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char * region, const int32_t * rawOffset, UErrorCode * ec);
457+
void ucal_set(UCalendar * cal, UCalendarDateFields field, int32_t value);
458+
void ucal_setMillis(UCalendar * cal, UDate dateTime, UErrorCode * status);
441459
void ucol_close(UCollator * coll);
442460
void ucol_closeElements(UCollationElements * elems);
443461
int32_t ucol_getOffset(const UCollationElements *elems);
@@ -457,6 +475,7 @@ int32_t ucurr_forLocale(const char * locale, UChar * buff, int32_t buffCapacity,
457475
const UChar * ucurr_getName(const UChar * currency, const char * locale, UCurrNameStyle nameStyle, UBool * isChoiceFormat, int32_t * len, UErrorCode * ec);
458476
void udat_close(UDateFormat * format);
459477
int32_t udat_countSymbols(const UDateFormat * fmt, UDateFormatSymbolType type);
478+
int32_t udat_format(const UDateFormat * format, UDate dateToFormat, UChar * result, int32_t resultLength, UFieldPosition * position, UErrorCode * status);
460479
int32_t udat_getSymbols(const UDateFormat * fmt, UDateFormatSymbolType type, int32_t symbolIndex, UChar * result, int32_t resultLength, UErrorCode * status);
461480
UDateFormat * udat_open(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char * locale, const UChar * tzID, int32_t tzIDLength, const UChar * pattern, int32_t patternLength, UErrorCode * status);
462481
void udat_setCalendar(UDateFormat * fmt, const UCalendar * calendarToSet);

0 commit comments

Comments
 (0)