Skip to content

Commit

Permalink
Bug 1947875 - Fix wrong use of Some() in AppDateTimeFormat::Format. r…
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Ivanovich authored and Yury Ivanovich committed Feb 25, 2025
1 parent 621c90f commit 9a596a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions intl/locale/AppDateTimeFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ nsresult AppDateTimeFormat::Format(const DateTimeFormat::ComponentsBag& aBag,

aStringOut.Truncate();

nsAutoCString str;
nsAutoString timeZoneID;
BuildTimeZoneString(aExplodedTime->tm_params, timeZoneID);

Expand All @@ -82,7 +81,8 @@ nsresult AppDateTimeFormat::Format(const DateTimeFormat::ComponentsBag& aBag,
auto dateTimePatternGenerator = genResult.unwrap();

auto result = DateTimeFormat::TryCreateFromComponents(
*sLocale, aBag, dateTimePatternGenerator.get(), Some(timeZoneID));
*sLocale, aBag, dateTimePatternGenerator.get(),
Some(Span<const char16_t>(timeZoneID.Data(), timeZoneID.Length())));
NS_ENSURE_TRUE(result.isOk(), NS_ERROR_FAILURE);
auto dateTimeFormat = result.unwrap();

Expand Down
10 changes: 10 additions & 0 deletions intl/locale/tests/gtest/TestAppDateTimeFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ TEST(AppDateTimeFormat, FormatPRExplodedTime)
ASSERT_TRUE(formattedTime.Find(u"2:47:00 PM") != kNotFound ||
formattedTime.Find(u"2:47:00\u202FPM") != kNotFound ||
formattedTime.Find(u"14:47:00") != kNotFound);

ComponentsBag components{};
components.weekday = mozilla::Some(DateTimeFormat::Text::Short);
components.timeZoneName = mozilla::Some(DateTimeFormat::TimeZoneName::Short);
// From above: Wed, 31 Dec 1969 14:47:00 -09:13
rv = AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
ASSERT_NS_SUCCEEDED(rv);
ASSERT_TRUE(formattedTime.Find(u"Wed") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"-09:13") != kNotFound ||
formattedTime.Find(u"-9:13") != kNotFound);
}

TEST(AppDateTimeFormat, DateFormatSelectors)
Expand Down

0 comments on commit 9a596a0

Please sign in to comment.