~ruther/guix-local

ref: b57b68aba645181b78bbdbef4ad908d60da03aa7 guix-local/gnu/packages/patches/icu4c-dtitvfmt-adopt-calendar.patch -rw-r--r-- 2.8 KiB
b57b68ab — Cayetano Santos gnu: open-logic: Move to hdl 30 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Retrieved from: <https://raw.githubusercontent.com/mozilla-firefox/firefox/refs/heads/main/intl/icu-patches/bug-1954138-dtitvfmt-adopt-calendar.diff>

diff --git a/source/i18n/dtitvfmt.cpp b/source/i18n/dtitvfmt.cpp
--- a/source/i18n/dtitvfmt.cpp
+++ b/source/i18n/dtitvfmt.cpp
@@ -631,16 +631,38 @@ DateIntervalFormat::getTimeZone() const
     if (fDateFormat != nullptr) {
         Mutex lock(&gFormatterMutex);
         return fDateFormat->getTimeZone();
     }
     // If fDateFormat is nullptr (unexpected), create default timezone.
     return *(TimeZone::createDefault());
 }
 
+void DateIntervalFormat::adoptCalendar(Calendar *calendarToAdopt) {
+    if (fDateFormat != nullptr) {
+        fDateFormat->adoptCalendar(calendarToAdopt);
+    }
+
+    // The fDateFormat has the primary calendar for the DateIntervalFormat and has
+    // ownership of any adopted Calendar; fFromCalendar and fToCalendar are internal
+    // work clones of that calendar.
+
+    delete fFromCalendar;
+    fFromCalendar = nullptr;
+
+    delete fToCalendar;
+    fToCalendar = nullptr;
+
+    const Calendar *calendar = fDateFormat->getCalendar();
+    if (calendar != nullptr) {
+        fFromCalendar = calendar->clone();
+        fToCalendar = calendar->clone();
+    }
+}
+
 void
 DateIntervalFormat::setContext(UDisplayContext value, UErrorCode& status)
 {
     if (U_FAILURE(status))
         return;
     if (static_cast<UDisplayContextType>(static_cast<uint32_t>(value) >> 8) == UDISPCTX_TYPE_CAPITALIZATION) {
         fCapitalizationContext = value;
     } else {
diff --git a/source/i18n/unicode/dtitvfmt.h b/source/i18n/unicode/dtitvfmt.h
--- a/source/i18n/unicode/dtitvfmt.h
+++ b/source/i18n/unicode/dtitvfmt.h
@@ -637,16 +637,23 @@ public:
     /**
      * Sets the time zone for the calendar used by this DateIntervalFormat object.
      * @param zone the new time zone.
      * @stable ICU 4.8
      */
     virtual void setTimeZone(const TimeZone& zone);
 
     /**
+     * Sets the calendar used by this DateIntervalFormat object. The caller no longer owns
+     * the Calendar object and should not delete it after this call.
+     * @param calendarToAdopt the Calendar to be adopted.
+     */
+    virtual void adoptCalendar(Calendar *calendarToAdopt);
+
+    /**
      * Set a particular UDisplayContext value in the formatter, such as
      * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. This causes the formatted
      * result to be capitalized appropriately for the context in which
      * it is intended to be used, considering both the locale and the
      * type of field at the beginning of the formatted result.
      * @param value The UDisplayContext value to set.
      * @param status Input/output status. If at entry this indicates a failure
      *               status, the function will do nothing; otherwise this will be