]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/wintzimpl.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************************
5 * Copyright (C) 2009-2013, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
11 ********************************************************************************
14 #include "unicode/utypes.h"
16 #if U_PLATFORM_USES_ONLY_WIN32_API && !UCONFIG_NO_FORMATTING
18 #include "wintzimpl.h"
20 #include "unicode/unistr.h"
21 #include "unicode/timezone.h"
22 #include "unicode/basictz.h"
27 #ifndef WIN32_LEAN_AND_MEAN
28 # define WIN32_LEAN_AND_MEAN
40 static UBool
getSystemTimeInformation(TimeZone
*tz
, SYSTEMTIME
&daylightDate
, SYSTEMTIME
&standardDate
, int32_t &bias
, int32_t &daylightBias
, int32_t &standardBias
) {
41 UErrorCode status
= U_ZERO_ERROR
;
43 BasicTimeZone
*btz
= (BasicTimeZone
*)tz
; // we should check type
44 InitialTimeZoneRule
*initial
= NULL
;
45 AnnualTimeZoneRule
*std
= NULL
, *dst
= NULL
;
47 btz
->getSimpleRulesNear(uprv_getUTCtime(), initial
, std
, dst
, status
);
48 if (U_SUCCESS(status
)) {
49 if (std
== NULL
|| dst
== NULL
) {
50 bias
= -1 * (initial
->getRawOffset()/60000);
53 // Do not use DST. Set 0 to all stadardDate/daylightDate fields
54 standardDate
.wYear
= standardDate
.wMonth
= standardDate
.wDayOfWeek
= standardDate
.wDay
=
55 standardDate
.wHour
= standardDate
.wMinute
= standardDate
.wSecond
= standardDate
.wMilliseconds
= 0;
56 daylightDate
.wYear
= daylightDate
.wMonth
= daylightDate
.wDayOfWeek
= daylightDate
.wDay
=
57 daylightDate
.wHour
= daylightDate
.wMinute
= daylightDate
.wSecond
= daylightDate
.wMilliseconds
= 0;
59 U_ASSERT(std
->getRule()->getDateRuleType() == DateTimeRule::DOW
);
60 U_ASSERT(dst
->getRule()->getDateRuleType() == DateTimeRule::DOW
);
62 bias
= -1 * (std
->getRawOffset()/60000);
64 daylightBias
= -1 * (dst
->getDSTSavings()/60000);
65 // Always use DOW type rule
66 int32_t hour
, min
, sec
, mil
;
67 standardDate
.wYear
= 0;
68 standardDate
.wMonth
= static_cast<WORD
>(std
->getRule()->getRuleMonth()) + 1;
69 standardDate
.wDay
= static_cast<WORD
>(std
->getRule()->getRuleWeekInMonth());
70 if (standardDate
.wDay
< 0) {
71 standardDate
.wDay
= 5;
73 standardDate
.wDayOfWeek
= static_cast<WORD
>(std
->getRule()->getRuleDayOfWeek()) - 1;
75 mil
= std
->getRule()->getRuleMillisInDay();
83 standardDate
.wHour
= static_cast<WORD
>(hour
);
84 standardDate
.wMinute
= static_cast<WORD
>(min
);
85 standardDate
.wSecond
= static_cast<WORD
>(sec
);
86 standardDate
.wMilliseconds
= static_cast<WORD
>(mil
);
88 daylightDate
.wYear
= 0;
89 daylightDate
.wMonth
= static_cast<WORD
>(dst
->getRule()->getRuleMonth()) + 1;
90 daylightDate
.wDay
= static_cast<WORD
>(dst
->getRule()->getRuleWeekInMonth());
91 if (daylightDate
.wDay
< 0) {
92 daylightDate
.wDay
= 5;
94 daylightDate
.wDayOfWeek
= static_cast<WORD
>(dst
->getRule()->getRuleDayOfWeek()) - 1;
96 mil
= dst
->getRule()->getRuleMillisInDay();
104 daylightDate
.wHour
= static_cast<WORD
>(hour
);
105 daylightDate
.wMinute
= static_cast<WORD
>(min
);
106 daylightDate
.wSecond
= static_cast<WORD
>(sec
);
107 daylightDate
.wMilliseconds
= static_cast<WORD
>(mil
);
120 static UBool
getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION
*zoneInfo
, const UChar
*icuid
, int32_t length
) {
121 UBool result
= FALSE
;
122 UnicodeString id
= UnicodeString(icuid
, length
);
123 TimeZone
*tz
= TimeZone::createTimeZone(id
);
127 int32_t daylightBias
;
128 int32_t standardBias
;
129 SYSTEMTIME daylightDate
;
130 SYSTEMTIME standardDate
;
132 if (getSystemTimeInformation(tz
, daylightDate
, standardDate
, bias
, daylightBias
, standardBias
)) {
133 uprv_memset(zoneInfo
, 0, sizeof(TIME_ZONE_INFORMATION
)); // We do not set standard/daylight names, so nullify first.
134 zoneInfo
->Bias
= bias
;
135 zoneInfo
->DaylightBias
= daylightBias
;
136 zoneInfo
->StandardBias
= standardBias
;
137 zoneInfo
->DaylightDate
= daylightDate
;
138 zoneInfo
->StandardDate
= standardDate
;
148 * Given the timezone icuid, fill in zoneInfo by calling auxillary functions that creates a timezone and extract the
149 * information to put into zoneInfo. This includes bias and standard time date and daylight saving date.
151 U_CAPI UBool U_EXPORT2
152 uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION
*zoneInfo
, const UChar
*icuid
, int32_t length
)
154 if (getWindowsTimeZoneInfo(zoneInfo
, icuid
, length
)) {