intl/icu/source/i18n/wintzimpl.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 ********************************************************************************
michael@0 3 * Copyright (C) 2009-2011, International Business Machines
michael@0 4 * Corporation and others. All Rights Reserved.
michael@0 5 ********************************************************************************
michael@0 6 *
michael@0 7 * File WINTZIMPL.CPP
michael@0 8 *
michael@0 9 ********************************************************************************
michael@0 10 */
michael@0 11
michael@0 12 #include "unicode/utypes.h"
michael@0 13
michael@0 14 #if U_PLATFORM_HAS_WIN32_API
michael@0 15
michael@0 16 #include "wintzimpl.h"
michael@0 17
michael@0 18 #include "unicode/unistr.h"
michael@0 19 #include "unicode/timezone.h"
michael@0 20 #include "unicode/basictz.h"
michael@0 21 #include "putilimp.h"
michael@0 22 #include "uassert.h"
michael@0 23 #include "cmemory.h"
michael@0 24
michael@0 25 # define WIN32_LEAN_AND_MEAN
michael@0 26 # define VC_EXTRALEAN
michael@0 27 # define NOUSER
michael@0 28 # define NOSERVICE
michael@0 29 # define NOIME
michael@0 30 # define NOMCX
michael@0 31
michael@0 32 #include <windows.h>
michael@0 33
michael@0 34 U_NAMESPACE_USE
michael@0 35
michael@0 36 static UBool getSystemTimeInformation(TimeZone *tz, SYSTEMTIME &daylightDate, SYSTEMTIME &standardDate, int32_t &bias, int32_t &daylightBias, int32_t &standardBias) {
michael@0 37 UErrorCode status = U_ZERO_ERROR;
michael@0 38 UBool result = TRUE;
michael@0 39 BasicTimeZone *btz = (BasicTimeZone*)tz; // we should check type
michael@0 40 InitialTimeZoneRule *initial = NULL;
michael@0 41 AnnualTimeZoneRule *std = NULL, *dst = NULL;
michael@0 42
michael@0 43 btz->getSimpleRulesNear(uprv_getUTCtime(), initial, std, dst, status);
michael@0 44 if (U_SUCCESS(status)) {
michael@0 45 if (std == NULL || dst == NULL) {
michael@0 46 bias = -1 * (initial->getRawOffset()/60000);
michael@0 47 standardBias = 0;
michael@0 48 daylightBias = 0;
michael@0 49 // Do not use DST. Set 0 to all stadardDate/daylightDate fields
michael@0 50 standardDate.wYear = standardDate.wMonth = standardDate.wDayOfWeek = standardDate.wDay =
michael@0 51 standardDate.wHour = standardDate.wMinute = standardDate.wSecond = standardDate.wMilliseconds = 0;
michael@0 52 daylightDate.wYear = daylightDate.wMonth = daylightDate.wDayOfWeek = daylightDate.wDay =
michael@0 53 daylightDate.wHour = daylightDate.wMinute = daylightDate.wSecond = daylightDate.wMilliseconds = 0;
michael@0 54 } else {
michael@0 55 U_ASSERT(std->getRule()->getDateRuleType() == DateTimeRule::DOW);
michael@0 56 U_ASSERT(dst->getRule()->getDateRuleType() == DateTimeRule::DOW);
michael@0 57
michael@0 58 bias = -1 * (std->getRawOffset()/60000);
michael@0 59 standardBias = 0;
michael@0 60 daylightBias = -1 * (dst->getDSTSavings()/60000);
michael@0 61 // Always use DOW type rule
michael@0 62 int32_t hour, min, sec, mil;
michael@0 63 standardDate.wYear = 0;
michael@0 64 standardDate.wMonth = std->getRule()->getRuleMonth() + 1;
michael@0 65 standardDate.wDay = std->getRule()->getRuleWeekInMonth();
michael@0 66 if (standardDate.wDay < 0) {
michael@0 67 standardDate.wDay = 5;
michael@0 68 }
michael@0 69 standardDate.wDayOfWeek = std->getRule()->getRuleDayOfWeek() - 1;
michael@0 70
michael@0 71 mil = std->getRule()->getRuleMillisInDay();
michael@0 72 hour = mil/3600000;
michael@0 73 mil %= 3600000;
michael@0 74 min = mil/60000;
michael@0 75 mil %= 60000;
michael@0 76 sec = mil/1000;
michael@0 77 mil %= 1000;
michael@0 78
michael@0 79 standardDate.wHour = hour;
michael@0 80 standardDate.wMinute = min;
michael@0 81 standardDate.wSecond = sec;
michael@0 82 standardDate.wMilliseconds = mil;
michael@0 83
michael@0 84 daylightDate.wYear = 0;
michael@0 85 daylightDate.wMonth = dst->getRule()->getRuleMonth() + 1;
michael@0 86 daylightDate.wDay = dst->getRule()->getRuleWeekInMonth();
michael@0 87 if (daylightDate.wDay < 0) {
michael@0 88 daylightDate.wDay = 5;
michael@0 89 }
michael@0 90 daylightDate.wDayOfWeek = dst->getRule()->getRuleDayOfWeek() - 1;
michael@0 91
michael@0 92 mil = dst->getRule()->getRuleMillisInDay();
michael@0 93 hour = mil/3600000;
michael@0 94 mil %= 3600000;
michael@0 95 min = mil/60000;
michael@0 96 mil %= 60000;
michael@0 97 sec = mil/1000;
michael@0 98 mil %= 1000;
michael@0 99
michael@0 100 daylightDate.wHour = hour;
michael@0 101 daylightDate.wMinute = min;
michael@0 102 daylightDate.wSecond = sec;
michael@0 103 daylightDate.wMilliseconds = mil;
michael@0 104 }
michael@0 105 } else {
michael@0 106 result = FALSE;
michael@0 107 }
michael@0 108
michael@0 109 delete initial;
michael@0 110 delete std;
michael@0 111 delete dst;
michael@0 112
michael@0 113 return result;
michael@0 114 }
michael@0 115
michael@0 116 static UBool getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length) {
michael@0 117 UBool result = FALSE;
michael@0 118 UnicodeString id = UnicodeString(icuid, length);
michael@0 119 TimeZone *tz = TimeZone::createTimeZone(id);
michael@0 120
michael@0 121 if (tz != NULL) {
michael@0 122 int32_t bias;
michael@0 123 int32_t daylightBias;
michael@0 124 int32_t standardBias;
michael@0 125 SYSTEMTIME daylightDate;
michael@0 126 SYSTEMTIME standardDate;
michael@0 127
michael@0 128 if (getSystemTimeInformation(tz, daylightDate, standardDate, bias, daylightBias, standardBias)) {
michael@0 129 uprv_memset(zoneInfo, 0, sizeof(TIME_ZONE_INFORMATION)); // We do not set standard/daylight names, so nullify first.
michael@0 130 zoneInfo->Bias = bias;
michael@0 131 zoneInfo->DaylightBias = daylightBias;
michael@0 132 zoneInfo->StandardBias = standardBias;
michael@0 133 zoneInfo->DaylightDate = daylightDate;
michael@0 134 zoneInfo->StandardDate = standardDate;
michael@0 135
michael@0 136 result = TRUE;
michael@0 137 }
michael@0 138 }
michael@0 139
michael@0 140 return result;
michael@0 141 }
michael@0 142
michael@0 143 /*
michael@0 144 * Given the timezone icuid, fill in zoneInfo by calling auxillary functions that creates a timezone and extract the
michael@0 145 * information to put into zoneInfo. This includes bias and standard time date and daylight saving date.
michael@0 146 */
michael@0 147 U_CAPI UBool U_EXPORT2
michael@0 148 uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length)
michael@0 149 {
michael@0 150 if (getWindowsTimeZoneInfo(zoneInfo, icuid, length)) {
michael@0 151 return TRUE;
michael@0 152 } else {
michael@0 153 return FALSE;
michael@0 154 }
michael@0 155 }
michael@0 156
michael@0 157 #endif

mercurial