FreeRDP
Loading...
Searching...
No Matches
TestTimeZoneIanaAlias.c
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <time.h>
5
6#include <winpr/wtypes.h>
7#include <winpr/string.h>
8#include <winpr/timezone.h>
9
10#if !defined(_WIN32)
11static BOOL test_tz(const char* iana, const char* expected)
12{
13 char key[128] = WINPR_C_ARRAY_INIT;
14 DYNAMIC_TIME_ZONE_INFORMATION tzif = WINPR_C_ARRAY_INIT;
15
16 // NOLINTNEXTLINE(concurrency-mt-unsafe)
17 if (setenv("TZ", iana, 1) != 0)
18 return FALSE;
19 tzset();
20
21 (void)GetDynamicTimeZoneInformation(&tzif);
22 if (ConvertWCharNToUtf8(tzif.TimeZoneKeyName, ARRAYSIZE(tzif.TimeZoneKeyName), key,
23 sizeof(key)) < 0)
24 return FALSE;
25
26 if (strcmp(key, expected) != 0)
27 {
28 (void)fprintf(stderr, "%s: expected time zone key '%s', got '%s'\n", iana, expected, key);
29 return FALSE;
30 }
31 return TRUE;
32}
33#endif
34
35int TestTimeZoneIanaAlias(int argc, char* argv[])
36{
37 WINPR_UNUSED(argc);
38 WINPR_UNUSED(argv);
39
40#if !defined(_WIN32)
41 /* current IANA names that CLDR's windowsZones.xml still spells the old way */
42 if (!test_tz("Asia/Kolkata", "India Standard Time"))
43 return -1;
44 if (!test_tz("Europe/Kyiv", "FLE Standard Time"))
45 return -1;
46 if (!test_tz("Asia/Kathmandu", "Nepal Standard Time"))
47 return -1;
48 if (!test_tz("Asia/Yangon", "Myanmar Standard Time"))
49 return -1;
50 /* in a multi zone entry of the fallback table (where the system does not resolve it to its
51 * tzdata link target Pacific/Guadalcanal, which maps to the same key) */
52 if (!test_tz("Pacific/Pohnpei", "Central Pacific Standard Time"))
53 return -1;
54 /* the old spelling keeps working */
55 if (!test_tz("Asia/Calcutta", "India Standard Time"))
56 return -1;
57 if (!test_tz("Europe/Kiev", "FLE Standard Time"))
58 return -1;
59 if (!test_tz("Asia/Katmandu", "Nepal Standard Time"))
60 return -1;
61 if (!test_tz("Asia/Rangoon", "Myanmar Standard Time"))
62 return -1;
63#endif
64
65 return 0;
66}