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

Commit

Permalink
Port First Year of Era Test (#33197)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh authored Nov 12, 2018
1 parent 52f1ba4 commit cd64b00
Showing 1 changed file with 23 additions and 0 deletions.
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"
);
}

}
}

0 comments on commit cd64b00

Please sign in to comment.