[Test, Timeout(300000)] // Can take a long time under NCrunch. public void BclThroughHistory_Scriptural() { Calendar bcl = new HebrewCalendar(); var noda = CalendarSystem.GetHebrewCalendar(HebrewMonthNumbering.Scriptural); // The min supported date/time starts part way through the year var minYear = bcl.GetYear(bcl.MinSupportedDateTime) + 1; // The max supported date/time ends part way through the year var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime) - 1; for (int year = minYear; year <= maxYear; year++) { int months = bcl.GetMonthsInYear(year); Assert.AreEqual(months, noda.GetMaxMonth(year)); for (int civilMonth = 1; civilMonth <= months; civilMonth++) { int scripturalMonth = HebrewMonthConverter.CivilToScriptural(year, civilMonth); Assert.AreEqual(bcl.GetDaysInMonth(year, civilMonth), noda.GetDaysInMonth(year, scripturalMonth), "Year: {0}; Month: {1} (civil)", year, civilMonth); for (int day = 1; day < bcl.GetDaysInMonth(year, civilMonth); day++) { DateTime bclDate = new DateTime(year, civilMonth, day, bcl); LocalDate nodaDate = new LocalDate(year, scripturalMonth, day, noda); Assert.AreEqual(bclDate, nodaDate.AtMidnight().ToDateTimeUnspecified()); Assert.AreEqual(nodaDate, LocalDateTime.FromDateTime(bclDate).WithCalendar(noda).Date); Assert.AreEqual(year, nodaDate.Year); Assert.AreEqual(scripturalMonth, nodaDate.Month); Assert.AreEqual(day, nodaDate.Day); } } } }
public void MonthsBetween_TimeOfDay() { var civil = CalendarSystem.GetHebrewCalendar(HebrewMonthNumbering.Civil); var start = new LocalDateTime(5774, 5, 10, 15, 0, civil); // 3pm var end = new LocalDateTime(5774, 7, 10, 5, 0, civil); // 5am // Would be 2, but the start time is later than the end time. Assert.AreEqual(1, Period.Between(start, end, PeriodUnits.Months).Months); }
public void PlusMonths_Overflow(HebrewMonthNumbering monthNumbering) { var calendar = CalendarSystem.GetHebrewCalendar(monthNumbering); // TODO: It would be nice to have an easy way of getting the smallest/largest LocalDate for // a calendar. Or possibly FromDayOfYear as well... instead, we'll just add/subtract 8 months instead var earlyDate = new LocalDate(calendar.MinYear, 1, 1, calendar); var lateDate = new LocalDate(calendar.MaxYear, 12, 1, calendar); Assert.Throws <OverflowException>(() => earlyDate.PlusMonths(-7)); Assert.Throws <OverflowException>(() => lateDate.PlusMonths(7)); }
public void MonthsBetween(string startText, int expectedMonths, string endText) { var civil = CalendarSystem.GetHebrewCalendar(HebrewMonthNumbering.Civil); var pattern = LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd") .WithTemplateValue(new LocalDate(5774, 1, 1, civil)); // Sample value in 2014 ISO var start = pattern.Parse(startText).Value; var end = pattern.Parse(endText).Value; Assert.AreEqual(expectedMonths, Period.Between(start, end, PeriodUnits.Months).Months); }
public void IsLeapYear() { var bcl = new HebrewCalendar(); var minYear = bcl.GetYear(bcl.MinSupportedDateTime); var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime); var noda = CalendarSystem.GetHebrewCalendar(HebrewMonthNumbering.Civil); for (int year = minYear; year <= maxYear; year++) { Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year)); } }
[TestCase("5400-09-30", 2, "5402-09-30")] // No truncation in Kislev (both 5503 and 5504 are long) public void SetYear(string startText, int years, string expectedEndText) { var civil = CalendarSystem.GetHebrewCalendar(HebrewMonthNumbering.Civil); var scriptural = CalendarSystem.GetHebrewCalendar(HebrewMonthNumbering.Scriptural); var pattern = LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd") .WithTemplateValue(new LocalDate(5774, 1, 1, scriptural)); // Sample value in 2014 ISO var start = pattern.Parse(startText).Value; var expectedEnd = pattern.Parse(expectedEndText).Value; Assert.AreEqual(expectedEnd, start.PlusYears(years)); // Check civil as well... the date should be the same (year, month, day) even though // the numbering is different. Assert.AreEqual(expectedEnd.WithCalendar(civil), start.WithCalendar(civil).PlusYears(years)); }