2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2009-06-16 05:56:50 +00:00
|
|
|
/*
|
|
|
|
********************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 2009-2013, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2009-06-16 05:56:50 +00:00
|
|
|
********************************************************************************
|
|
|
|
*
|
|
|
|
* File WINTZIMPL.CPP
|
|
|
|
*
|
|
|
|
********************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2017-04-07 18:26:45 +00:00
|
|
|
#if U_PLATFORM_USES_ONLY_WIN32_API && !UCONFIG_NO_FORMATTING
|
2009-06-16 05:56:50 +00:00
|
|
|
|
|
|
|
#include "wintzimpl.h"
|
|
|
|
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
#include "unicode/timezone.h"
|
|
|
|
#include "unicode/basictz.h"
|
|
|
|
#include "putilimp.h"
|
|
|
|
#include "uassert.h"
|
2009-11-06 05:48:37 +00:00
|
|
|
#include "cmemory.h"
|
2009-06-16 05:56:50 +00:00
|
|
|
|
2017-03-21 01:03:49 +00:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
2009-06-16 05:56:50 +00:00
|
|
|
# define WIN32_LEAN_AND_MEAN
|
2017-03-21 01:03:49 +00:00
|
|
|
#endif
|
2009-06-16 05:56:50 +00:00
|
|
|
# define VC_EXTRALEAN
|
|
|
|
# define NOUSER
|
|
|
|
# define NOSERVICE
|
|
|
|
# define NOIME
|
|
|
|
# define NOMCX
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
2009-08-18 06:46:32 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2009-06-16 05:56:50 +00:00
|
|
|
static UBool getSystemTimeInformation(TimeZone *tz, SYSTEMTIME &daylightDate, SYSTEMTIME &standardDate, int32_t &bias, int32_t &daylightBias, int32_t &standardBias) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UBool result = TRUE;
|
|
|
|
BasicTimeZone *btz = (BasicTimeZone*)tz; // we should check type
|
|
|
|
InitialTimeZoneRule *initial = NULL;
|
|
|
|
AnnualTimeZoneRule *std = NULL, *dst = NULL;
|
|
|
|
|
|
|
|
btz->getSimpleRulesNear(uprv_getUTCtime(), initial, std, dst, status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
if (std == NULL || dst == NULL) {
|
|
|
|
bias = -1 * (initial->getRawOffset()/60000);
|
2009-11-06 05:22:08 +00:00
|
|
|
standardBias = 0;
|
2009-06-16 05:56:50 +00:00
|
|
|
daylightBias = 0;
|
|
|
|
// Do not use DST. Set 0 to all stadardDate/daylightDate fields
|
|
|
|
standardDate.wYear = standardDate.wMonth = standardDate.wDayOfWeek = standardDate.wDay =
|
|
|
|
standardDate.wHour = standardDate.wMinute = standardDate.wSecond = standardDate.wMilliseconds = 0;
|
|
|
|
daylightDate.wYear = daylightDate.wMonth = daylightDate.wDayOfWeek = daylightDate.wDay =
|
|
|
|
daylightDate.wHour = daylightDate.wMinute = daylightDate.wSecond = daylightDate.wMilliseconds = 0;
|
|
|
|
} else {
|
|
|
|
U_ASSERT(std->getRule()->getDateRuleType() == DateTimeRule::DOW);
|
|
|
|
U_ASSERT(dst->getRule()->getDateRuleType() == DateTimeRule::DOW);
|
|
|
|
|
|
|
|
bias = -1 * (std->getRawOffset()/60000);
|
2009-11-06 05:22:08 +00:00
|
|
|
standardBias = 0;
|
2009-06-16 05:56:50 +00:00
|
|
|
daylightBias = -1 * (dst->getDSTSavings()/60000);
|
|
|
|
// Always use DOW type rule
|
|
|
|
int32_t hour, min, sec, mil;
|
|
|
|
standardDate.wYear = 0;
|
2017-07-22 01:11:59 +00:00
|
|
|
standardDate.wMonth = static_cast<WORD>(std->getRule()->getRuleMonth()) + 1;
|
|
|
|
standardDate.wDay = static_cast<WORD>(std->getRule()->getRuleWeekInMonth());
|
2009-06-16 05:56:50 +00:00
|
|
|
if (standardDate.wDay < 0) {
|
|
|
|
standardDate.wDay = 5;
|
|
|
|
}
|
2017-07-22 01:11:59 +00:00
|
|
|
standardDate.wDayOfWeek = static_cast<WORD>(std->getRule()->getRuleDayOfWeek()) - 1;
|
2009-06-16 05:56:50 +00:00
|
|
|
|
|
|
|
mil = std->getRule()->getRuleMillisInDay();
|
|
|
|
hour = mil/3600000;
|
|
|
|
mil %= 3600000;
|
|
|
|
min = mil/60000;
|
|
|
|
mil %= 60000;
|
|
|
|
sec = mil/1000;
|
|
|
|
mil %= 1000;
|
|
|
|
|
2017-07-22 01:11:59 +00:00
|
|
|
standardDate.wHour = static_cast<WORD>(hour);
|
|
|
|
standardDate.wMinute = static_cast<WORD>(min);
|
|
|
|
standardDate.wSecond = static_cast<WORD>(sec);
|
|
|
|
standardDate.wMilliseconds = static_cast<WORD>(mil);
|
2009-06-16 05:56:50 +00:00
|
|
|
|
|
|
|
daylightDate.wYear = 0;
|
2017-07-22 01:11:59 +00:00
|
|
|
daylightDate.wMonth = static_cast<WORD>(dst->getRule()->getRuleMonth()) + 1;
|
|
|
|
daylightDate.wDay = static_cast<WORD>(dst->getRule()->getRuleWeekInMonth());
|
2009-06-16 05:56:50 +00:00
|
|
|
if (daylightDate.wDay < 0) {
|
|
|
|
daylightDate.wDay = 5;
|
|
|
|
}
|
2017-07-22 01:11:59 +00:00
|
|
|
daylightDate.wDayOfWeek = static_cast<WORD>(dst->getRule()->getRuleDayOfWeek()) - 1;
|
2009-06-16 05:56:50 +00:00
|
|
|
|
|
|
|
mil = dst->getRule()->getRuleMillisInDay();
|
|
|
|
hour = mil/3600000;
|
|
|
|
mil %= 3600000;
|
|
|
|
min = mil/60000;
|
|
|
|
mil %= 60000;
|
|
|
|
sec = mil/1000;
|
|
|
|
mil %= 1000;
|
|
|
|
|
2017-07-22 01:11:59 +00:00
|
|
|
daylightDate.wHour = static_cast<WORD>(hour);
|
|
|
|
daylightDate.wMinute = static_cast<WORD>(min);
|
|
|
|
daylightDate.wSecond = static_cast<WORD>(sec);
|
|
|
|
daylightDate.wMilliseconds = static_cast<WORD>(mil);
|
2009-06-16 05:56:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete initial;
|
|
|
|
delete std;
|
|
|
|
delete dst;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UBool getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length) {
|
|
|
|
UBool result = FALSE;
|
|
|
|
UnicodeString id = UnicodeString(icuid, length);
|
|
|
|
TimeZone *tz = TimeZone::createTimeZone(id);
|
|
|
|
|
|
|
|
if (tz != NULL) {
|
|
|
|
int32_t bias;
|
|
|
|
int32_t daylightBias;
|
|
|
|
int32_t standardBias;
|
|
|
|
SYSTEMTIME daylightDate;
|
|
|
|
SYSTEMTIME standardDate;
|
2009-11-06 05:48:37 +00:00
|
|
|
|
2009-06-16 05:56:50 +00:00
|
|
|
if (getSystemTimeInformation(tz, daylightDate, standardDate, bias, daylightBias, standardBias)) {
|
2009-11-06 05:48:37 +00:00
|
|
|
uprv_memset(zoneInfo, 0, sizeof(TIME_ZONE_INFORMATION)); // We do not set standard/daylight names, so nullify first.
|
2009-06-16 05:56:50 +00:00
|
|
|
zoneInfo->Bias = bias;
|
|
|
|
zoneInfo->DaylightBias = daylightBias;
|
|
|
|
zoneInfo->StandardBias = standardBias;
|
|
|
|
zoneInfo->DaylightDate = daylightDate;
|
|
|
|
zoneInfo->StandardDate = standardDate;
|
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given the timezone icuid, fill in zoneInfo by calling auxillary functions that creates a timezone and extract the
|
|
|
|
* information to put into zoneInfo. This includes bias and standard time date and daylight saving date.
|
|
|
|
*/
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length)
|
|
|
|
{
|
|
|
|
if (getWindowsTimeZoneInfo(zoneInfo, icuid, length)) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|