def test_YEARFRAC_yearfrac_basis_3(self): # From Excel docs. self.assertAlmostEqual( date.YEARFRAC(dt(2012, 1, 1), dt(2012, 7, 30), 3), 0.57808219) self.assertAlmostEqual( date.YEARFRAC(dt(2008, 1, 1), dt(2015, 4, 20), 3), 7.304109589) self.assertAlmostEqual( date.YEARFRAC(dt(2024, 1, 1), dt(2025, 1, 1), 3), 1.0027397260274)
def test_YEARFRAC_yearfrac_basis_0(self): # From Excel docs. self.assertAlmostEqual( date.YEARFRAC(dt(2012, 1, 1), dt(2012, 7, 30), 0), 0.58055556) self.assertAlmostEqual(date.YEARFRAC(dt(2008, 1, 1), dt(2015, 4, 20)), 7.30277777777778) self.assertAlmostEqual( date.YEARFRAC(dt(2008, 1, 1), dt(2015, 4, 20), 0), 7.30277777777778) self.assertAlmostEqual( date.YEARFRAC(dt(2024, 1, 1), dt(2025, 1, 1), 0), 1)
def test_YEARFRAC_yearfrac_inverted(self): self.assertAlmostEqual(date.YEARFRAC(dt(2015, 4, 20), dt(2008, 1, 1)), date.YEARFRAC(dt(2008, 1, 1), dt(2015, 4, 20)))
def test_YEARFRAC_yearfrac_basis_4(self): self.assertAlmostEqual( date.YEARFRAC(dt(2008, 1, 1), dt(2015, 4, 20), 4), 7.302777778) self.assertAlmostEqual( date.YEARFRAC(dt(2024, 1, 1), dt(2025, 1, 1), 4), 1)
def test_YEARFRAC_yearfrac_basis_2(self): self.assertAlmostEqual( date.YEARFRAC(dt(2008, 1, 1), dt(2015, 4, 20), 2), 7.405555556) self.assertAlmostEqual( date.YEARFRAC(dt(2024, 1, 1), dt(2025, 1, 1), 2), 1.01666666666667)
def test_YEARFRAC_yearfrac_basis_1(self): # From Excel docs. self.assertAlmostEqual( date.YEARFRAC(dt(2012, 1, 1), dt(2012, 7, 30), 1), 0.57650273)
def test_YEARFRAC_basis_must_be_between_0_and_4(self): self.assertIsInstance(date.YEARFRAC(1, 2, 5), xlerrors.ValueExcelError) self.assertIsInstance(date.YEARFRAC(1, 2, -1), xlerrors.ValueExcelError)
def test_YEARFRAC_end_date_must_be_after_epoch(self): self.assertIsInstance(date.YEARFRAC(dt(1900, 1, 1), -1), xlerrors.ValueExcelError)
def test_YEARFRAC_start_date_must_after_epoch(self): self.assertIsInstance(date.YEARFRAC(dt(1800, 1, 1), 0), xlerrors.ValueExcelError)
def test_YEARFRAC_end_date_must_be_datetime(self): self.assertIsInstance(date.YEARFRAC(1, 'bad'), xlerrors.ValueExcelError)
def test_YEARFRAC_start_date_must_be_datetime(self): self.assertIsInstance(date.YEARFRAC('bad', 1), xlerrors.ValueExcelError)