Debian Codegraph @

intl/icu-patches/bug-1954138-dtitvfmt-adopt-calendar.diff

raw
1 diff --git a/intl/icu/source/i18n/dtitvfmt.cpp b/intl/icu/source/i18n/dtitvfmt.cpp
2 --- a/intl/icu/source/i18n/dtitvfmt.cpp
3 +++ b/intl/icu/source/i18n/dtitvfmt.cpp
4 @@ -631,16 +631,38 @@ DateIntervalFormat::getTimeZone() const
5 if (fDateFormat != nullptr) {
6 Mutex lock(&gFormatterMutex);
7 return fDateFormat->getTimeZone();
8 }
9 // If fDateFormat is nullptr (unexpected), create default timezone.
10 return *(TimeZone::createDefault());
11 }
12
13 +void DateIntervalFormat::adoptCalendar(Calendar *calendarToAdopt) {
14 + if (fDateFormat != nullptr) {
15 + fDateFormat->adoptCalendar(calendarToAdopt);
16 + }
17 +
18 + // The fDateFormat has the primary calendar for the DateIntervalFormat and has
19 + // ownership of any adopted Calendar; fFromCalendar and fToCalendar are internal
20 + // work clones of that calendar.
21 +
22 + delete fFromCalendar;
23 + fFromCalendar = nullptr;
24 +
25 + delete fToCalendar;
26 + fToCalendar = nullptr;
27 +
28 + const Calendar *calendar = fDateFormat->getCalendar();
29 + if (calendar != nullptr) {
30 + fFromCalendar = calendar->clone();
31 + fToCalendar = calendar->clone();
32 + }
33 +}
34 +
35 void
36 DateIntervalFormat::setContext(UDisplayContext value, UErrorCode& status)
37 {
38 if (U_FAILURE(status))
39 return;
40 if (static_cast<UDisplayContextType>(static_cast<uint32_t>(value) >> 8) == UDISPCTX_TYPE_CAPITALIZATION) {
41 fCapitalizationContext = value;
42 } else {
43 diff --git a/intl/icu/source/i18n/unicode/dtitvfmt.h b/intl/icu/source/i18n/unicode/dtitvfmt.h
44 --- a/intl/icu/source/i18n/unicode/dtitvfmt.h
45 +++ b/intl/icu/source/i18n/unicode/dtitvfmt.h
46 @@ -637,16 +637,23 @@ public:
47 /**
48 * Sets the time zone for the calendar used by this DateIntervalFormat object.
49 * @param zone the new time zone.
50 * @stable ICU 4.8
51 */
52 virtual void setTimeZone(const TimeZone& zone);
53
54 /**
55 + * Sets the calendar used by this DateIntervalFormat object. The caller no longer owns
56 + * the Calendar object and should not delete it after this call.
57 + * @param calendarToAdopt the Calendar to be adopted.
58 + */
59 + virtual void adoptCalendar(Calendar *calendarToAdopt);
60 +
61 + /**
62 * Set a particular UDisplayContext value in the formatter, such as
63 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. This causes the formatted
64 * result to be capitalized appropriately for the context in which
65 * it is intended to be used, considering both the locale and the
66 * type of field at the beginning of the formatted result.
67 * @param value The UDisplayContext value to set.
68 * @param status Input/output status. If at entry this indicates a failure
69 * status, the function will do nothing; otherwise this will be