diff --git a/intl/locale/AppDateTimeFormat.cpp b/intl/locale/AppDateTimeFormat.cpp index d967d312a443ed..cafac1a41f00f9 100644 --- a/intl/locale/AppDateTimeFormat.cpp +++ b/intl/locale/AppDateTimeFormat.cpp @@ -73,7 +73,6 @@ nsresult AppDateTimeFormat::Format(const DateTimeFormat::ComponentsBag& aBag, aStringOut.Truncate(); - nsAutoCString str; nsAutoString timeZoneID; BuildTimeZoneString(aExplodedTime->tm_params, timeZoneID); @@ -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(timeZoneID.Data(), timeZoneID.Length()))); NS_ENSURE_TRUE(result.isOk(), NS_ERROR_FAILURE); auto dateTimeFormat = result.unwrap(); diff --git a/intl/locale/tests/gtest/TestAppDateTimeFormat.cpp b/intl/locale/tests/gtest/TestAppDateTimeFormat.cpp index a83b37342873f9..52eaf48fb10e30 100644 --- a/intl/locale/tests/gtest/TestAppDateTimeFormat.cpp +++ b/intl/locale/tests/gtest/TestAppDateTimeFormat.cpp @@ -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)