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);
+ }
}
}
{
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!;
}
// 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 "/";
}
}
/// <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
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);