Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fr-CA culture time formatting and parsing #56443

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,17 @@ public void JapaneseAbbreviatedEnglishEraNamesTest()
Assert.Equal(i + 1, ci.DateTimeFormat.GetEra(eraNames[i]));
}
}

[Fact]
public void TestFrenchCanadaTimeFormat()
{
CultureInfo ci = CultureInfo.GetCultureInfo("fr-CA");
Assert.Equal(":", ci.DateTimeFormat.TimeSeparator);

DateTime time = new DateTime(2021, 10, 1, 5, 36, 50);
string formattedTime = time.ToString("HH 'h' mm 'min' ss 's'", ci);
DateTime dt = DateTime.Parse(formattedTime, ci);
Assert.Equal(time.TimeOfDay, dt.TimeOfDay);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1926,14 +1926,23 @@ internal string TimeSeparator
{
if (_sTimeSeparator == null && !GlobalizationMode.Invariant)
{
string? longTimeFormat = ShouldUseUserOverrideNlsData ? NlsGetTimeFormatString() : IcuGetTimeFormatString();
if (string.IsNullOrEmpty(longTimeFormat))
// fr-CA culture uses time format as "HH 'h' mm 'min' ss 's'" which we cannot derive the time separator from such pattern.
// We special case such culture and force ':' as time separator.
if (_sName == "fr-CA")
{
longTimeFormat = LongTimes[0];
_sTimeSeparator = ":";
}
else
{
string? longTimeFormat = ShouldUseUserOverrideNlsData ? NlsGetTimeFormatString() : IcuGetTimeFormatString();
if (string.IsNullOrEmpty(longTimeFormat))
{
longTimeFormat = LongTimes[0];
}

// Compute STIME from time format
_sTimeSeparator = GetTimeSeparator(longTimeFormat);
// Compute STIME from time format
_sTimeSeparator = GetTimeSeparator(longTimeFormat);
}
}
return _sTimeSeparator!;
}
Expand All @@ -1956,7 +1965,7 @@ internal string DateSeparator(CalendarId calendarId)
// changing the default pattern is likely will happen in the near future which can easily break formatting
// and parsing.
// We are forcing here the date separator to '/' to ensure the parsing is not going to break when changing
// the default short date pattern. The application still can override this in the code by DateTimeFormatInfo.DateSeparartor.
// the default short date pattern. The application still can override this in the code by DateTimeFormatInfo.DateSeparator.
return "/";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private static CultureInfo GetCultureByName(string name)
}

/// <summary>
/// Return a specific culture. A tad irrelevent now since we always
/// Return a specific culture. A tad irrelevant now since we always
/// return valid data for neutral locales.
///
/// Note that there's interesting behavior that tries to find a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,16 @@ internal TokenHashValue[] CreateTokenHashTable()
InsertHash(temp, TimeSeparator, TokenType.SEP_Time, 0);
}

if (_name == "fr-CA")
{
InsertHash(temp, " h", TokenType.SEP_HourSuff, 0);
InsertHash(temp, " h ", TokenType.SEP_HourSuff, 0);
InsertHash(temp, " min", TokenType.SEP_MinuteSuff, 0);
InsertHash(temp, " min ", TokenType.SEP_MinuteSuff, 0);
InsertHash(temp, " s", TokenType.SEP_SecondSuff, 0);
InsertHash(temp, " s ", TokenType.SEP_SecondSuff, 0);
}

InsertHash(temp, AMDesignator, TokenType.SEP_Am | TokenType.Am, 0);
InsertHash(temp, PMDesignator, TokenType.SEP_Pm | TokenType.Pm, 1);

Expand Down