tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bug-1954138-dtitvfmt-adopt-calendar.diff (2778B)


      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 @@ -630,16 +630,38 @@ DateIntervalFormat::getTimeZone() const
      5 {
      6     if (fDateFormat != nullptr) {
      7         Mutex lock(&gFormatterMutex);
      8         return fDateFormat->getTimeZone();
      9     }
     10     // If fDateFormat is nullptr (unexpected), create default timezone.
     11     return *(TimeZone::createDefault());
     12 }
     13 + 
     14 +void DateIntervalFormat::adoptCalendar(Calendar *calendarToAdopt) {
     15 +    if (fDateFormat != nullptr) {
     16 +        fDateFormat->adoptCalendar(calendarToAdopt);
     17 +    }
     18 +
     19 +    // The fDateFormat has the primary calendar for the DateIntervalFormat and has
     20 +    // ownership of any adopted Calendar; fFromCalendar and fToCalendar are internal
     21 +    // work clones of that calendar.
     22 +
     23 +    delete fFromCalendar;
     24 +    fFromCalendar = nullptr;
     25 +
     26 +    delete fToCalendar;
     27 +    fToCalendar = nullptr;
     28 +
     29 +    const Calendar *calendar = fDateFormat->getCalendar();
     30 +    if (calendar != nullptr) {
     31 +        fFromCalendar = calendar->clone();
     32 +        fToCalendar = calendar->clone();
     33 +    }
     34 +}
     35 
     36 void
     37 DateIntervalFormat::setContext(UDisplayContext value, UErrorCode& status)
     38 {
     39     if (U_FAILURE(status))
     40         return;
     41     if (static_cast<UDisplayContextType>(static_cast<uint32_t>(value) >> 8) == UDISPCTX_TYPE_CAPITALIZATION) {
     42         fCapitalizationContext = value;
     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 @@ -625,16 +625,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     U_I18N_API 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 +    U_I18N_API 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