Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@@ -161,5 +161,28 @@ namespace System.Globalization.Tests
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"
);
}
}
}