Skip to content

Commit b598ce9

Browse files
authored
Clarify MatchAbbreviatedMonthName comment (#92405)
1 parent 6d589b7 commit b598ce9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/libraries/System.Globalization.Calendars/tests/Misc/MiscCalendars.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,19 @@ public static void JapaneseTest()
4242
DateTime dTest = jCal.ToDateTime(1, 1, 8, 0, 0, 0, 0, 4);
4343
Assert.Equal(dTest, new DateTime(1989, 1, 8));
4444
}
45+
46+
[Theory]
47+
[InlineData(@"Thg 1", 1)]
48+
[InlineData(@"Thg 2", 2)]
49+
[InlineData(@"Thg 10", 10)]
50+
[InlineData(@"Thg 11", 11)]
51+
[InlineData(@"Thg 12", 12)]
52+
//[InlineData(@"Thg 13", 13)] Needs supported calendar with 13 months
53+
public static void VietnameseTest_MatchAbbreviatedMonthName_ContinuesSearchAfterMatch(string monthAbberavition, int expectedMonthNum)
54+
{
55+
var dtfi = new System.Globalization.CultureInfo("vi-VN").DateTimeFormat;
56+
dtfi.AbbreviatedMonthNames = new string[] { "Thg 1", "Thg 2", "Thg 3", "Thg 4", "Thg 5", "Thg 6", "Thg 7", "Thg 8", "Thg 9", "Thg 10", "Thg 11", "Thg 12", "Thg 13" }; // 13 months
57+
Assert.Equal(expectedMonthNum, DateTime.ParseExact(monthAbberavition, "MMM", dtfi).Month);
58+
}
4559
}
4660
}

src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,9 +3352,9 @@ private static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormat
33523352
{
33533353
// Scan the month names (note that some calendars has 13 months) and find
33543354
// the matching month name which has the max string length.
3355-
// We need to do this because some cultures (e.g. "cs-CZ") which have
3356-
// abbreviated month names with the same prefix.
3357-
int monthsInYear = (dtfi.GetMonthName(13).Length == 0 ? 12 : 13);
3355+
// We need to do this because some cultures which have abbreviated
3356+
// month names with the same prefix (e.g. "vi-VN" culture has those conflicts "Thg1", "Thg10", "Thg11")
3357+
int monthsInYear = (dtfi.GetAbbreviatedMonthName(13).Length == 0 ? 12 : 13);
33583358
for (int i = 1; i <= monthsInYear; i++)
33593359
{
33603360
string searchStr = dtfi.GetAbbreviatedMonthName(i);

0 commit comments

Comments
 (0)