Skip to content

Commit

Permalink
[release/8.0][browser] Fix failures in CalendarTestBase affecting s…
Browse files Browse the repository at this point in the history
…everal globalization tests (#99407)

* Partial backport of #90881.

* Backport updated expected test results.

* Update should be only for v8. Browser/node were correct in the original form.
  • Loading branch information
ilonatommy committed Mar 8, 2024
1 parent db167d9 commit 53e2082
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ public static IEnumerable<object[]> AbbreviatedMonthGenitiveNames_Get_TestData_H
yield return new object[] { new CultureInfo("ms-BN").DateTimeFormat, new string[] { "Jan", "Feb", "Mac", "Apr", "Mei", "Jun", "Jul", "Ogo", "Sep", "Okt", "Nov", "Dis", "" } };
yield return new object[] { new CultureInfo("ms-MY").DateTimeFormat, new string[] { "Jan", "Feb", "Mac", "Apr", "Mei", "Jun", "Jul", "Ogo", "Sep", "Okt", "Nov", "Dis", "" } };
yield return new object[] { new CultureInfo("ms-SG").DateTimeFormat, new string[] { "Jan", "Feb", "Mac", "Apr", "Mei", "Jun", "Jul", "Ogo", "Sep", "Okt", "Nov", "Dis", "" } };
yield return new object[] { new CultureInfo("nb-NO").DateTimeFormat, new string[] { "jan.", "feb.", "mar.", "apr.", "mai", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "des.", "" } };
yield return new object[] { new CultureInfo("no-NO").DateTimeFormat, new string[] { "jan.", "feb.", "mar.", "apr.", "mai", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "des.", "" } };
string[] norwegianMonths = PlatformDetection.IsBrowserDomSupported ? // dotnet responds like non-browser
new string [] { "jan.", "feb.", "mar.", "apr.", "mai", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "des.", "" } :
new string [] { "jan.", "feb.", "mars", "apr.", "mai", "juni", "juli", "aug.", "sep.", "okt.", "nov.", "des.", "" };
yield return new object[] { new CultureInfo("nb-NO").DateTimeFormat, norwegianMonths };
yield return new object[] { new CultureInfo("no-NO").DateTimeFormat, norwegianMonths };
string[] dutchMonths = PlatformDetection.IsNodeJS ? // NodeJs responds like dotnet
new string[] { "jan.", "feb.", "mrt.", "apr.", "mei", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "dec.", "" } :
new string[] { "jan", "feb", "mrt", "apr", "mei", "jun", "jul", "aug", "sep", "okt", "nov", "dec", "" };
Expand Down
13 changes: 10 additions & 3 deletions src/mono/wasm/runtime/hybrid-globalization/culture-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function mono_wasm_get_culture_info(culture: MonoStringRef, dst: number,

function getAmPmDesignators(locale: any)
{
const pmTime = new Date("August 19, 1975 12:15:30"); // do not change, some PM hours result in hour digits change, e.g. 13 -> 01 or 1
const amTime = new Date("August 19, 1975 11:15:30"); // do not change, some AM hours result in hour digits change, e.g. 9 -> 09
const pmTime = new Date("August 19, 1975 12:15:33"); // do not change, some PM hours result in hour digits change, e.g. 13 -> 01 or 1
const amTime = new Date("August 19, 1975 11:15:33"); // do not change, some AM hours result in hour digits change, e.g. 9 -> 09
const pmDesignator = getDesignator(pmTime, locale);
const amDesignator = getDesignator(amTime, locale);
return {
Expand All @@ -59,7 +59,14 @@ function getAmPmDesignators(locale: any)

function getDesignator(time: Date, locale: string)
{
const withDesignator = time.toLocaleTimeString(locale, { hourCycle: "h12"});
let withDesignator = time.toLocaleTimeString(locale, { hourCycle: "h12"});
const localizedZero = (0).toLocaleString(locale);
if (withDesignator.includes(localizedZero))
{
// in v8>=11.8 "12" changes to "0" for ja-JP
const localizedTwelve = (12).toLocaleString(locale);
withDesignator = withDesignator.replace(localizedZero, localizedTwelve);
}
const withoutDesignator = time.toLocaleTimeString(locale, { hourCycle: "h24"});
const designator = withDesignator.replace(withoutDesignator, "").trim();
if (new RegExp("[0-9]$").test(designator)){
Expand Down

0 comments on commit 53e2082

Please sign in to comment.