Skip to content

Commit

Permalink
Improve time zone display names on Unix (#48931)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Mar 24, 2021
1 parent aab9aa6 commit a0fc08e
Show file tree
Hide file tree
Showing 11 changed files with 758 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ internal enum TimeZoneDisplayNameType
Generic = 0,
Standard = 1,
DaylightSavings = 2,
GenericLocation = 3,
ExemplarCity = 4,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,33 @@
// (U_ICU_VERSION_MAJOR_NUM < 52)
// The following APIs are not supported in the ICU versions less than 52. We need to define them manually.
// 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.
U_CAPI int32_t U_EXPORT2 ucal_getWindowsTimeZoneID(const UChar* id, int32_t len,UChar* winid, int32_t winidCapacity, UErrorCode* status);
U_CAPI int32_t U_EXPORT2 ucal_getTimeZoneIDForWindowsID(const UChar* winid, int32_t len, const char* region, UChar* id, int32_t idCapacity, UErrorCode* status);
U_CAPI int32_t U_EXPORT2 ucal_getWindowsTimeZoneID(const UChar* id, int32_t len, UChar* winid, int32_t winidCapacity, UErrorCode* status);
#endif

// List of all functions from the ICU libraries that are used in the System.Globalization.Native.so
#define FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \
PER_FUNCTION_BLOCK(u_charsToUChars, libicuuc, true) \
PER_FUNCTION_BLOCK(u_getVersion, libicuuc, true) \
PER_FUNCTION_BLOCK(u_strcmp, libicuuc, true) \
PER_FUNCTION_BLOCK(u_strcpy, libicuuc, true) \
PER_FUNCTION_BLOCK(u_strlen, libicuuc, true) \
PER_FUNCTION_BLOCK(u_strncpy, libicuuc, true) \
PER_FUNCTION_BLOCK(u_tolower, libicuuc, true) \
PER_FUNCTION_BLOCK(u_toupper, libicuuc, true) \
PER_FUNCTION_BLOCK(u_uastrcpy, libicuuc, true) \
PER_FUNCTION_BLOCK(ucal_add, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_close, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_get, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_getAttribute, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_getKeywordValuesForLocale, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_getLimit, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_getNow, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_getTimeZoneDisplayName, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_open, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_openTimeZoneIDEnumeration, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_set, libicui18n, true) \
PER_FUNCTION_BLOCK(ucal_setMillis, libicui18n, true) \
PER_FUNCTION_BLOCK(ucol_close, libicui18n, true) \
PER_FUNCTION_BLOCK(ucol_closeElements, libicui18n, true) \
PER_FUNCTION_BLOCK(ucol_getOffset, libicui18n, true) \
Expand All @@ -96,6 +102,7 @@ U_CAPI int32_t U_EXPORT2 ucal_getTimeZoneIDForWindowsID(const UChar* winid, int3
PER_FUNCTION_BLOCK(ucol_strcoll, libicui18n, true) \
PER_FUNCTION_BLOCK(udat_close, libicui18n, true) \
PER_FUNCTION_BLOCK(udat_countSymbols, libicui18n, true) \
PER_FUNCTION_BLOCK(udat_format, libicui18n, true) \
PER_FUNCTION_BLOCK(udat_getSymbols, libicui18n, true) \
PER_FUNCTION_BLOCK(udat_open, libicui18n, true) \
PER_FUNCTION_BLOCK(udat_setCalendar, libicui18n, true) \
Expand Down Expand Up @@ -202,21 +209,27 @@ FOR_ALL_ICU_FUNCTIONS
// to the functions of the selected version of ICU in the initialization.
#define u_charsToUChars(...) u_charsToUChars_ptr(__VA_ARGS__)
#define u_getVersion(...) u_getVersion_ptr(__VA_ARGS__)
#define u_strcmp(...) u_strcmp_ptr(__VA_ARGS__)
#define u_strcpy(...) u_strcpy_ptr(__VA_ARGS__)
#define u_strlen(...) u_strlen_ptr(__VA_ARGS__)
#define u_strncpy(...) u_strncpy_ptr(__VA_ARGS__)
#define u_tolower(...) u_tolower_ptr(__VA_ARGS__)
#define u_toupper(...) u_toupper_ptr(__VA_ARGS__)
#define u_uastrcpy(...) u_uastrcpy_ptr(__VA_ARGS__)
#define ucal_add(...) ucal_add_ptr(__VA_ARGS__)
#define ucal_close(...) ucal_close_ptr(__VA_ARGS__)
#define ucal_get(...) ucal_get_ptr(__VA_ARGS__)
#define ucal_getAttribute(...) ucal_getAttribute_ptr(__VA_ARGS__)
#define ucal_getKeywordValuesForLocale(...) ucal_getKeywordValuesForLocale_ptr(__VA_ARGS__)
#define ucal_getLimit(...) ucal_getLimit_ptr(__VA_ARGS__)
#define ucal_getNow(...) ucal_getNow_ptr(__VA_ARGS__)
#define ucal_getTimeZoneDisplayName(...) ucal_getTimeZoneDisplayName_ptr(__VA_ARGS__)
#define ucal_getTimeZoneIDForWindowsID(...) ucal_getTimeZoneIDForWindowsID_ptr(__VA_ARGS__)
#define ucal_getWindowsTimeZoneID(...) ucal_getWindowsTimeZoneID_ptr(__VA_ARGS__)
#define ucal_open(...) ucal_open_ptr(__VA_ARGS__)
#define ucal_openTimeZoneIDEnumeration(...) ucal_openTimeZoneIDEnumeration_ptr(__VA_ARGS__)
#define ucal_set(...) ucal_set_ptr(__VA_ARGS__)
#define ucal_setMillis(...) ucal_setMillis_ptr(__VA_ARGS__)
#define ucol_close(...) ucol_close_ptr(__VA_ARGS__)
#define ucol_closeElements(...) ucol_closeElements_ptr(__VA_ARGS__)
#define ucol_getOffset(...) ucol_getOffset_ptr(__VA_ARGS__)
Expand All @@ -241,6 +254,7 @@ FOR_ALL_ICU_FUNCTIONS
#define ucurr_getName(...) ucurr_getName_ptr(__VA_ARGS__)
#define udat_close(...) udat_close_ptr(__VA_ARGS__)
#define udat_countSymbols(...) udat_countSymbols_ptr(__VA_ARGS__)
#define udat_format(...) udat_format_ptr(__VA_ARGS__)
#define udat_getSymbols(...) udat_getSymbols_ptr(__VA_ARGS__)
#define udat_open(...) udat_open_ptr(__VA_ARGS__)
#define udat_setCalendar(...) udat_setCalendar_ptr(__VA_ARGS__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct UBreakIterator UBreakIterator;
typedef int8_t UBool;
typedef uint16_t UChar;
typedef int32_t UChar32;
typedef double UDate;
typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH];

typedef void* UNumberFormat;
Expand Down Expand Up @@ -369,6 +370,12 @@ typedef enum UCollationResult {
UCOL_LESS = -1
} UCollationResult;

typedef enum USystemTimeZoneType {
UCAL_ZONE_TYPE_ANY,
UCAL_ZONE_TYPE_CANONICAL,
UCAL_ZONE_TYPE_CANONICAL_LOCATION
} USystemTimeZoneType;

enum {
UIDNA_ERROR_EMPTY_LABEL = 1,
UIDNA_ERROR_LABEL_TOO_LONG = 2,
Expand Down Expand Up @@ -419,25 +426,36 @@ typedef struct UIDNAInfo {
int32_t reservedI3;
} UIDNAInfo;

typedef struct UFieldPosition {
int32_t field;
int32_t beginIndex;
int32_t endIndex;
} UFieldPosition;


void u_charsToUChars(const char * cs, UChar * us, int32_t length);
void u_getVersion(UVersionInfo versionArray);
int32_t u_strlen(const UChar * s);
int32_t u_strcmp(const UChar * s1, const UChar * s2);
UChar * u_strcpy(UChar * dst, const UChar * src);
UChar * u_strncpy(UChar * dst, const UChar * src, int32_t n);
UChar32 u_tolower(UChar32 c);
UChar32 u_toupper(UChar32 c);
UChar* u_uastrcpy(UChar * dst, const char * src);
void ucal_add(UCalendar * cal, UCalendarDateFields field, int32_t amount, UErrorCode * status);
void ucal_close(UCalendar * cal);
int32_t ucal_get(const UCalendar * cal, UCalendarDateFields field, UErrorCode * status);
int32_t ucal_getAttribute(const UCalendar * cal, UCalendarAttribute attr);
UEnumeration * ucal_getKeywordValuesForLocale(const char * key, const char * locale, UBool commonlyUsed, UErrorCode * status);
int32_t ucal_getLimit(const UCalendar * cal, UCalendarDateFields field, UCalendarLimitType type, UErrorCode * status);
UDate ucal_getNow(void);
int32_t ucal_getTimeZoneDisplayName(const UCalendar * cal, UCalendarDisplayNameType type, const char * locale, UChar * result, int32_t resultLength, UErrorCode * status);
UCalendar * ucal_open(const UChar * zoneID, int32_t len, const char * locale, UCalendarType type, UErrorCode * status);
void ucal_set(UCalendar * cal, UCalendarDateFields field, int32_t value);
int32_t ucal_getTimeZoneIDForWindowsID(const UChar * winid, int32_t len, const char * region, UChar * id, int32_t idCapacity, UErrorCode * status);
int32_t ucal_getWindowsTimeZoneID(const UChar * id, int32_t len, UChar * winid, int32_t winidCapacity, UErrorCode * status);
UCalendar * ucal_open(const UChar * zoneID, int32_t len, const char * locale, UCalendarType type, UErrorCode * status);
UEnumeration * ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char * region, const int32_t * rawOffset, UErrorCode * ec);
void ucal_set(UCalendar * cal, UCalendarDateFields field, int32_t value);
void ucal_setMillis(UCalendar * cal, UDate dateTime, UErrorCode * status);
void ucol_close(UCollator * coll);
void ucol_closeElements(UCollationElements * elems);
int32_t ucol_getOffset(const UCollationElements *elems);
Expand All @@ -457,6 +475,7 @@ int32_t ucurr_forLocale(const char * locale, UChar * buff, int32_t buffCapacity,
const UChar * ucurr_getName(const UChar * currency, const char * locale, UCurrNameStyle nameStyle, UBool * isChoiceFormat, int32_t * len, UErrorCode * ec);
void udat_close(UDateFormat * format);
int32_t udat_countSymbols(const UDateFormat * fmt, UDateFormatSymbolType type);
int32_t udat_format(const UDateFormat * format, UDate dateToFormat, UChar * result, int32_t resultLength, UFieldPosition * position, UErrorCode * status);
int32_t udat_getSymbols(const UDateFormat * fmt, UDateFormatSymbolType type, int32_t symbolIndex, UChar * result, int32_t resultLength, UErrorCode * status);
UDateFormat * udat_open(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char * locale, const UChar * tzID, int32_t tzIDLength, const UChar * pattern, int32_t patternLength, UErrorCode * status);
void udat_setCalendar(UDateFormat * fmt, const UCalendar * calendarToSet);
Expand Down
Loading

0 comments on commit a0fc08e

Please sign in to comment.