Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Port First Year of Era Test #33197

Merged
merged 1 commit into from
Nov 12, 2018
Merged
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 @@ -161,5 +161,28 @@ public void TestHebrewMonths()
dt = ci.DateTimeFormat.Calendar.AddMonths(dt, 1);
}
}

[Fact]
public void TestFirstYearOfJapaneseEra()
{
DateTimeFormatInfo jpnFormat = new CultureInfo("ja-JP").DateTimeFormat;
jpnFormat.Calendar = new JapaneseCalendar();

string pattern = "gg yyyy'\u5E74' MM'\u6708' dd'\u65E5'"; // "gg yyyy'年' MM'月' dd'日'"
DateTime dt = new DateTime(1989, 01, 08); // Start of Heisei Era

string formattedDateWithGannen = "\u5E73\u6210 \u5143\u5E74 01\u6708 08\u65E5"; // 平成 元年 01月 08日
string formattedDate = dt.ToString(pattern, jpnFormat);

Assert.True(DateTime.TryParseExact(formattedDate, pattern, jpnFormat, DateTimeStyles.None, out DateTime parsedDate));
Assert.Equal(dt, parsedDate);

// If the formatting with Gan-nen is supported, then parsing should succeed. otherwise parsing should fail.
Assert.True(formattedDate.IndexOf("\u5143" /* 元 */, StringComparison.Ordinal) >= 0 ==
DateTime.TryParseExact(formattedDateWithGannen, pattern, jpnFormat, DateTimeStyles.None, out parsedDate),
$"Parsing '{formattedDateWithGannen}' result should match if '{formattedDate}' has Gan-nen symbol"
);
}

}
}