1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | // |
5 | |
6 | #include <stdint.h> |
7 | #include <unistd.h> |
8 | |
9 | #include "icushim.h" |
10 | #include "locale.hpp" |
11 | #include "holders.h" |
12 | #include "errors.h" |
13 | |
14 | /* |
15 | These values should be kept in sync with the managed Interop.GlobalizationInterop.TimeZoneDisplayNameType enum. |
16 | */ |
17 | enum TimeZoneDisplayNameType : int32_t |
18 | { |
19 | Generic = 0, |
20 | Standard = 1, |
21 | DaylightSavings = 2, |
22 | }; |
23 | |
24 | /* |
25 | Gets the localized display name for the specified time zone. |
26 | */ |
27 | extern "C" ResultCode GlobalizationNative_GetTimeZoneDisplayName( |
28 | const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength) |
29 | { |
30 | UErrorCode err = U_ZERO_ERROR; |
31 | char locale[ULOC_FULLNAME_CAPACITY]; |
32 | GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err); |
33 | |
34 | int32_t timeZoneIdLength = -1; // timeZoneId is NULL-terminated |
35 | UCalendar* calendar = ucal_open(timeZoneId, timeZoneIdLength, locale, UCAL_DEFAULT, &err); |
36 | UCalendarHolder calendarHolder(calendar, err); |
37 | |
38 | // TODO (https://github.com/dotnet/corefx/issues/5741): need to support Generic names, but ICU "C" api |
39 | // has no public option for this. For now, just use the ICU standard name for both Standard and Generic |
40 | // (which is the same behavior on Windows with the mincore TIME_ZONE_INFORMATION APIs). |
41 | ucal_getTimeZoneDisplayName( |
42 | calendar, type == DaylightSavings ? UCAL_DST : UCAL_STANDARD, locale, result, resultLength, &err); |
43 | |
44 | return GetResultCode(err); |
45 | } |
46 | |