mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 23:10:40 +00:00
ICU-4152 Use TimeZone::getEquivalentID to handle aliases.
X-SVN-Rev: 19020
This commit is contained in:
parent
69ffe9f919
commit
ae8baeb57d
6 changed files with 50 additions and 24 deletions
|
@ -377,7 +377,7 @@ static LONG getTZI(const char *winid, TZI *tzi)
|
|||
return result;
|
||||
}
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
U_CAPI UBool U_EXPORT2
|
||||
uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length)
|
||||
{
|
||||
const char *winid;
|
||||
|
@ -385,6 +385,11 @@ uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid,
|
|||
LONG result;
|
||||
|
||||
winid = findWindowsZoneID(icuid, length);
|
||||
|
||||
if (winid == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
result = getTZI(winid, &tzi);
|
||||
|
||||
if (result == ERROR_SUCCESS) {
|
||||
|
@ -394,11 +399,10 @@ uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid,
|
|||
zoneInfo->DaylightDate = tzi.daylightDate;
|
||||
zoneInfo->StandardDate = tzi.standardDate;
|
||||
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Can't find a match - use Windows default zone. */
|
||||
GetTimeZoneInformation(zoneInfo);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -26,7 +26,7 @@ U_CDECL_BEGIN
|
|||
typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION;
|
||||
U_CDECL_END
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
U_CAPI UBool U_EXPORT2
|
||||
uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length);
|
||||
|
||||
U_CAPI const char* U_EXPORT2
|
||||
|
|
|
@ -140,20 +140,12 @@ UnicodeString &Win32DateFormat::format(Calendar &cal, UnicodeString &appendTo, F
|
|||
FILETIME ft;
|
||||
SYSTEMTIME st_gmt;
|
||||
SYSTEMTIME st_local;
|
||||
UnicodeString zoneID;
|
||||
TIME_ZONE_INFORMATION tzi = *fTZI;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const TimeZone &tz = cal.getTimeZone();
|
||||
int64_t uct, uft;
|
||||
|
||||
tz.getID(zoneID);
|
||||
|
||||
if (zoneID.compare(fZoneID) != 0) {
|
||||
UnicodeString icuid;
|
||||
|
||||
tz.getID(icuid);
|
||||
uprv_getWindowsTimeZoneInfo(&tzi, icuid.getBuffer(), icuid.length());
|
||||
}
|
||||
setTimeZoneInfo(&tzi, tz);
|
||||
|
||||
uct = utmscale_fromInt64((int64_t) cal.getTime(status), UDTS_ICU4C_TIME, &status);
|
||||
uft = utmscale_toInt64(uct, UDTS_WINDOWS_FILE_TIME, &status);
|
||||
|
@ -210,7 +202,7 @@ void Win32DateFormat::adoptCalendar(Calendar *newCalendar)
|
|||
delete fCalendar;
|
||||
fCalendar = newCalendar;
|
||||
|
||||
setTimeZoneInfo(fCalendar->getTimeZone());
|
||||
fZoneID = setTimeZoneInfo(fTZI, fCalendar->getTimeZone());
|
||||
}
|
||||
|
||||
void Win32DateFormat::setCalendar(const Calendar &newCalendar)
|
||||
|
@ -220,13 +212,13 @@ void Win32DateFormat::setCalendar(const Calendar &newCalendar)
|
|||
|
||||
void Win32DateFormat::adoptTimeZone(TimeZone *zoneToAdopt)
|
||||
{
|
||||
setTimeZoneInfo(*zoneToAdopt);
|
||||
fZoneID = setTimeZoneInfo(fTZI, *zoneToAdopt);
|
||||
fCalendar->adoptTimeZone(zoneToAdopt);
|
||||
}
|
||||
|
||||
void Win32DateFormat::setTimeZone(const TimeZone& zone)
|
||||
{
|
||||
setTimeZoneInfo(zone);
|
||||
fZoneID = setTimeZoneInfo(fTZI, zone);
|
||||
fCalendar->setTimeZone(zone);
|
||||
}
|
||||
|
||||
|
@ -282,7 +274,7 @@ void Win32DateFormat::formatTime(const SYSTEMTIME *st, UnicodeString &appendTo)
|
|||
}
|
||||
}
|
||||
|
||||
void Win32DateFormat::setTimeZoneInfo(const TimeZone &zone)
|
||||
UnicodeString Win32DateFormat::setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const
|
||||
{
|
||||
UnicodeString zoneID;
|
||||
|
||||
|
@ -291,11 +283,26 @@ void Win32DateFormat::setTimeZoneInfo(const TimeZone &zone)
|
|||
if (zoneID.compare(fZoneID) != 0) {
|
||||
UnicodeString icuid;
|
||||
|
||||
fZoneID = zoneID;
|
||||
|
||||
zone.getID(icuid);
|
||||
uprv_getWindowsTimeZoneInfo(fTZI, icuid.getBuffer(), icuid.length());
|
||||
if (! uprv_getWindowsTimeZoneInfo(tzi, icuid.getBuffer(), icuid.length())) {
|
||||
UBool found = FALSE;
|
||||
int32_t ec = TimeZone::countEquivalentIDs(icuid);
|
||||
|
||||
for (int z = 0; z < ec; z += 1) {
|
||||
UnicodeString equiv = TimeZone::getEquivalentID(icuid, z);
|
||||
|
||||
if (found = uprv_getWindowsTimeZoneInfo(tzi, equiv.getBuffer(), equiv.length())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! found) {
|
||||
GetTimeZoneInformation(tzi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return zoneID;
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
|
|
@ -124,7 +124,7 @@ private:
|
|||
void formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const;
|
||||
void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const;
|
||||
|
||||
void setTimeZoneInfo(const TimeZone &zone);
|
||||
UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const;
|
||||
|
||||
UnicodeString *fDateTimeMsg;
|
||||
DateFormat::EStyle fTimeStyle;
|
||||
|
|
|
@ -61,7 +61,7 @@ void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &nam
|
|||
Locale saveDefaultLocale = Locale::getDefault();
|
||||
if (exec) {
|
||||
saveDefaultTimeZone = TimeZone::createDefault();
|
||||
TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles" /*"PST"*/);
|
||||
TimeZone *tz = TimeZone::createTimeZone("PST");
|
||||
TimeZone::setDefault(*tz);
|
||||
delete tz;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
|
|
@ -78,7 +78,22 @@ void Win32DateTimeTest::testLocales(TestLog *log)
|
|||
TIME_ZONE_INFORMATION tzi;
|
||||
|
||||
tz->getID(zoneID);
|
||||
uprv_getWindowsTimeZoneInfo(&tzi, zoneID.getBuffer(), zoneID.length());
|
||||
if (! uprv_getWindowsTimeZoneInfo(&tzi, zoneID.getBuffer(), zoneID.length())) {
|
||||
UBool found = FALSE;
|
||||
int32_t ec = TimeZone::countEquivalentIDs(zoneID);
|
||||
|
||||
for (int z = 0; z < ec; z += 1) {
|
||||
UnicodeString equiv = TimeZone::getEquivalentID(zoneID, z);
|
||||
|
||||
if (found = uprv_getWindowsTimeZoneInfo(&tzi, equiv.getBuffer(), equiv.length())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! found) {
|
||||
GetTimeZoneInformation(&tzi);
|
||||
}
|
||||
}
|
||||
|
||||
GetSystemTime(&st);
|
||||
SystemTimeToFileTime(&st, &ft);
|
||||
|
|
Loading…
Add table
Reference in a new issue