Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 57ba13c

Browse files
tarekghstephentoub
authored andcommitted
Add Hebrew Months test (#26915)
* Add Hebrew Months test * add some spaces
1 parent 1fc770a commit 57ba13c

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public void SeparatorsTest()
5959
expectedFormattedString = formattedTime.Replace(timeSep, dtfi.TimeSeparator);
6060
Assert.Equal(expectedFormattedString, d.ToString("HH:mm:ss", dtfi));
6161
}
62-
62+
6363
[Theory]
6464
[MemberData(nameof(DateTimeFormatInfo_TestData))]
6565
public void NativeCalendarNameTest(DateTimeFormatInfo dtfi, Calendar calendar, string nativeCalendarName)
6666
{
67-
try
67+
try
6868
{
6969
dtfi.Calendar = calendar;
7070
Assert.Equal(nativeCalendarName, dtfi.NativeCalendarName);
@@ -77,8 +77,8 @@ public void NativeCalendarNameTest(DateTimeFormatInfo dtfi, Calendar calendar, s
7777
Assert.True(calendar is PersianCalendar, "Exception can occur only with PersianCalendar");
7878
}
7979
else // !PlatformDetection.IsWindows
80-
{
81-
Assert.True(calendar is HijriCalendar || calendar is UmAlQuraCalendar || calendar is ThaiBuddhistCalendar ||
80+
{
81+
Assert.True(calendar is HijriCalendar || calendar is UmAlQuraCalendar || calendar is ThaiBuddhistCalendar ||
8282
calendar is HebrewCalendar || calendar is KoreanCalendar, "failed to set the calendar on DTFI");
8383
}
8484
}
@@ -131,7 +131,35 @@ public void ShortestDayNamesTest(string cultureName)
131131
for (DayOfWeek day=DayOfWeek.Sunday; day <= DayOfWeek.Saturday; day++)
132132
{
133133
Assert.Equal(shortestDayNames[(int) day], dtfi.GetShortestDayName(day));
134-
}
134+
}
135+
}
136+
137+
[Fact]
138+
public void TestHebrewMonths()
139+
{
140+
CultureInfo ci = new CultureInfo("he-IL");
141+
ci.DateTimeFormat.Calendar = new HebrewCalendar();
142+
143+
Assert.Equal(13, ci.DateTimeFormat.MonthNames.Length);
144+
Assert.Equal(13, ci.DateTimeFormat.MonthGenitiveNames.Length);
145+
Assert.Equal(13, ci.DateTimeFormat.AbbreviatedMonthNames.Length);
146+
Assert.Equal(13, ci.DateTimeFormat.AbbreviatedMonthGenitiveNames.Length);
147+
148+
DateTime dt = ci.DateTimeFormat.Calendar.ToDateTime(5779, 1, 1, 0, 0, 0, 0); // leap year
149+
for (int i = 0; i < 13; i++)
150+
{
151+
string formatted = dt.ToString(ci.DateTimeFormat.LongDatePattern, ci);
152+
Assert.Equal(dt, DateTime.ParseExact(formatted, ci.DateTimeFormat.LongDatePattern, ci));
153+
dt = ci.DateTimeFormat.Calendar.AddMonths(dt, 1);
154+
}
155+
156+
dt = ci.DateTimeFormat.Calendar.ToDateTime(5778, 1, 1, 0, 0, 0, 0); // non leap year
157+
for (int i = 0; i < 12; i++)
158+
{
159+
string formatted = dt.ToString(ci.DateTimeFormat.LongDatePattern, ci);
160+
Assert.Equal(dt, DateTime.ParseExact(formatted, ci.DateTimeFormat.LongDatePattern, ci));
161+
dt = ci.DateTimeFormat.Calendar.AddMonths(dt, 1);
162+
}
135163
}
136164
}
137165
}

0 commit comments

Comments
 (0)