public void ToStringBclEquality(CultureInfo culture) { // The BCL *sometimes* use the genitive month names for year/month, even though I don't // think it should. There may be more complexity here, but for the moment, we'll just skip the cultures we // expect to fail. (We would definitely want to know if new cultures started failing.) string[] expectedFailures = { "ast-ES", "ca-AD", "ca-ES", "ca-ES-valencia", "ca-FR", "ca-IT", "es-PE", "es-UY", "gl-ES", "oc-FR" }; if (expectedFailures.Contains(culture.Name)) { return; } Calendar calendar = culture.Calendar; var calendarSystem = BclCalendars.CalendarSystemForCalendar(calendar); if (calendarSystem is null) { // We can't map this calendar system correctly yet; the test would be invalid. return; } // Use the year/month containing "January 1st 2022 ISO" but in the target culture's calendar. var date = new LocalDate(2022, 1, 1).WithCalendar(calendarSystem); var yearMonth = date.ToYearMonth(); using (CultureSaver.SetCultures(culture)) { var bclText = date.ToDateTimeUnspecified().ToString(culture.DateTimeFormat.YearMonthPattern, culture); var nodaText1 = yearMonth.ToString(); var nodaText2 = yearMonth.ToString("G", culture); Assert.AreEqual(bclText, nodaText1); Assert.AreEqual(nodaText1, nodaText2); } }
public void ToStringTest_Iso(CultureInfo culture) { var yearMonth = new YearMonth(2022, 1); using (CultureSaver.SetCultures(culture)) { Assert.AreEqual(yearMonth.ToString(culture.DateTimeFormat.YearMonthPattern, culture), yearMonth.ToString()); } }
public void ToString_NoFormat() { LocalTime time = new LocalTime(14, 15, 12, 123); Offset offset = Offset.FromHours(1); OffsetTime offsetDate = new OffsetTime(time, offset); using (CultureSaver.SetCultures(CultureInfo.InvariantCulture)) { Assert.AreEqual("14:15:12+01", offsetDate.ToString()); } }
public void ToString_NoFormat() { LocalDate date = new LocalDate(2012, 10, 6); Offset offset = Offset.FromHours(1); OffsetDate offsetDate = new OffsetDate(date, offset); using (CultureSaver.SetCultures(CultureInfo.InvariantCulture)) { Assert.AreEqual("2012-10-06+01", offsetDate.ToString()); } }