+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
-* Copyright (C) 2007-2011, International Business Machines Corporation and
+* Copyright (C) 2007-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
-#include <typeinfo> // for 'typeid' to work
+#include "utypeinfo.h" // for 'typeid' to work
#include "unicode/utypes.h"
#include "cmemory.h"
#include "uvector.h"
#include "gregoimp.h"
+#include "uassert.h"
U_NAMESPACE_BEGIN
digits[i++] = number % 10;
number /= 10;
} while (number != 0);
- length = i;
+ length = static_cast<uint8_t>(i);
} else {
// fixed digits
for (i = 0; i < length; i++) {
/*
* Create a default TZNAME from TZID
*/
-static void getDefaultTZName(const UnicodeString tzid, UBool isDST, UnicodeString& zonename) {
+static void getDefaultTZName(const UnicodeString &tzid, UBool isDST, UnicodeString& zonename) {
zonename = tzid;
if (isDST) {
zonename += UNICODE_STRING_SIMPLE("(DST)");
UnicodeString rrule = *((UnicodeString*)dates->elementAt(0));
int32_t month, dayOfWeek, nthDayOfWeek, dayOfMonth = 0;
int32_t days[7];
- int32_t daysCount = sizeof(days)/sizeof(days[0]);
+ int32_t daysCount = UPRV_LENGTHOF(days);
UDate until;
parseRRULE(rrule, month, dayOfWeek, nthDayOfWeek, days, daysCount, until, status);
UDate tmp_until;
int32_t tmp_month, tmp_dayOfWeek, tmp_nthDayOfWeek;
int32_t tmp_days[7];
- int32_t tmp_daysCount = sizeof(tmp_days)/sizeof(tmp_days[0]);
+ int32_t tmp_daysCount = UPRV_LENGTHOF(tmp_days);
parseRRULE(rrule, tmp_month, tmp_dayOfWeek, tmp_nthDayOfWeek, tmp_days, tmp_daysCount, tmp_until, status);
if (U_FAILURE(status)) {
return NULL;
}
void
-VTimeZone::write(UDate start, UnicodeString& result, UErrorCode& status) /*const*/ {
+VTimeZone::write(UDate start, UnicodeString& result, UErrorCode& status) const {
result.remove();
VTZWriter writer(result);
write(start, writer, status);
}
void
-VTimeZone::writeSimple(UDate time, UnicodeString& result, UErrorCode& status) /*const*/ {
+VTimeZone::writeSimple(UDate time, UnicodeString& result, UErrorCode& status) const {
result.remove();
VTZWriter writer(result);
writeSimple(time, writer, status);
}
UBool
-VTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/ {
+VTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
return tz->getNextTransition(base, inclusive, result);
}
UBool
-VTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/ {
+VTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
return tz->getPreviousTransition(base, inclusive, result);
}
int32_t
-VTimeZone::countTransitionRules(UErrorCode& status) /*const*/ {
+VTimeZone::countTransitionRules(UErrorCode& status) const {
return tz->countTransitionRules(status);
}
void
VTimeZone::getTimeZoneRules(const InitialTimeZoneRule*& initial,
const TimeZoneRule* trsrules[], int32_t& trscount,
- UErrorCode& status) /*const*/ {
+ UErrorCode& status) const {
tz->getTimeZoneRules(initial, trsrules, trscount, status);
}
}
}
} else {
- UVector *customProps = NULL;
+ UnicodeString icutzprop;
+ UVector customProps(nullptr, uhash_compareUnicodeString, status);
if (olsonzid.length() > 0 && icutzver.length() > 0) {
- customProps = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status);
- if (U_FAILURE(status)) {
- return;
- }
- UnicodeString *icutzprop = new UnicodeString(ICU_TZINFO_PROP);
- icutzprop->append(olsonzid);
- icutzprop->append((UChar)0x005B/*'['*/);
- icutzprop->append(icutzver);
- icutzprop->append((UChar)0x005D/*']'*/);
- customProps->addElement(icutzprop, status);
- if (U_FAILURE(status)) {
- delete icutzprop;
- delete customProps;
- return;
- }
+ icutzprop.append(olsonzid);
+ icutzprop.append(u'[');
+ icutzprop.append(icutzver);
+ icutzprop.append(u']');
+ customProps.addElement(&icutzprop, status);
}
- writeZone(writer, *tz, customProps, status);
- delete customProps;
+ writeZone(writer, *tz, &customProps, status);
}
}
void
-VTimeZone::write(UDate start, VTZWriter& writer, UErrorCode& status) /*const*/ {
+VTimeZone::write(UDate start, VTZWriter& writer, UErrorCode& status) const {
if (U_FAILURE(status)) {
return;
}
}
void
-VTimeZone::writeSimple(UDate time, VTZWriter& writer, UErrorCode& status) /*const*/ {
+VTimeZone::writeSimple(UDate time, VTZWriter& writer, UErrorCode& status) const {
if (U_FAILURE(status)) {
return;
}
if (U_FAILURE(status)) {
goto cleanupWriteZone;
}
- writeFinalRule(w, TRUE, finalDstRule,
- dstFromOffset - dstFromDSTSavings, dstFromDSTSavings, dstStartTime, status);
+ UDate nextStart;
+ UBool nextStartAvail = finalDstRule->getNextStart(dstUntilTime, dstFromOffset - dstFromDSTSavings, dstFromDSTSavings, false, nextStart);
+ U_ASSERT(nextStartAvail);
+ if (nextStartAvail) {
+ writeFinalRule(w, TRUE, finalDstRule,
+ dstFromOffset - dstFromDSTSavings, dstFromDSTSavings, nextStart, status);
+ }
}
}
if (U_FAILURE(status)) {
// Use a single rule if possible
if (isEquivalentDateRule(stdMonth, stdWeekInMonth, stdDayOfWeek, finalStdRule->getRule())) {
writeZonePropsByDOW(w, FALSE, stdName, stdFromOffset, stdToOffset,
- stdMonth, stdWeekInMonth, stdDayOfWeek, stdStartTime, MAX_MILLIS, status);
+ stdMonth, stdWeekInMonth, stdDayOfWeek, stdStartTime, MAX_MILLIS, status);
} else {
// Not equivalent rule - write out two different rules
writeZonePropsByDOW(w, FALSE, stdName, stdFromOffset, stdToOffset,
if (U_FAILURE(status)) {
goto cleanupWriteZone;
}
- writeFinalRule(w, FALSE, finalStdRule,
- stdFromOffset - stdFromDSTSavings, stdFromDSTSavings, stdStartTime, status);
+ UDate nextStart;
+ UBool nextStartAvail = finalStdRule->getNextStart(stdUntilTime, stdFromOffset - stdFromDSTSavings, stdFromDSTSavings, false, nextStart);
+ U_ASSERT(nextStartAvail);
+ if (nextStartAvail) {
+ writeFinalRule(w, FALSE, finalStdRule,
+ stdFromOffset - stdFromDSTSavings, stdFromDSTSavings, nextStart, status);
+ }
}
}
if (U_FAILURE(status)) {