def test_delta(self): sd = date(2018, 12, 1) self.assertEqual(-1, LCalendars.delta(sd, date(2018, 12, 2))) self.assertEqual( -1, LCalendars.delta(LunarDate.from_solar(sd), date(2018, 12, 2))) self.assertEqual( 4, LCalendars.delta(LunarDate(2018, 1, 6), LunarDate(2018, 1, 2)))
def test_ndays(self): self.assertEqual(354, LCalendars.ndays(2018)) self.assertEqual(30, LCalendars.ndays(2018, 12)) self.assertEqual(30, LCalendars.ndays(2017, 6, 1)) with self.assertRaises(ValueError): LCalendars.ndays(2017, 7, 1) with self.assertRaises(ValueError): LCalendars.ndays(2017, 13)
def test_leap_check(self): self.assertTrue(LCalendars.is_leap_month(2017, 6)) self.assertFalse(LCalendars.is_leap_month(2017, 7))
def test_leap_check(self): self.assertTrue(LCalendars.leap_month(2017) == 6) self.assertFalse(LCalendars.leap_month(2017) == 7)
def _resolve(self, year): return LCalendars.create_solar_date(year, term_index=self.index)
def _resolve(self, year): if self._reverse == 0: day = self.day else: day = LCalendars.ndays(year, self.month) - self.day + 1 return LunarDate(year, self.month, day)
def test_create_specific_dates(self): today = LunarDate.today() self.assertEqual(1, LCalendars.delta(LunarDate.tomorrow(), today)) self.assertEqual(-1, LCalendars.delta(LunarDate.yesterday(), today)) self.assertEqual(5, LCalendars.delta(today.after(5), today)) self.assertEqual(-5, LCalendars.delta(today.before(5), today))
def test_leap_check(self): self.assertTrue(LCalendars.leap_month(2017) == 6) self.assertFalse(LCalendars.leap_month(2017) == 7) self.assertIn(2017, LCalendars.get_leap_years(6)) self.assertIn(2017, LCalendars.get_leap_years()) self.assertEqual(0, len(LCalendars.get_leap_years(14)))