/** * @param DateTime $startDate * @param DateTime $endDate * @return TimeSpan */ public static function asInterval(DateTime $startDate, DateTime $endDate) { $newThis = new TimeSpan(); $newThis->checkStartEndDateAndSetInterval($startDate, $endDate); $newThis->setStartDate($startDate); $newThis->setEndDate($endDate); return $newThis; }
/** * @param DebtAmortizator $result */ private function processResult(DebtAmortizator $result) { $this->assertEquals("40000", $result->getDebtPrincipal()); $this->assertEquals("6", $result->getDebtNoOfCompoundingPeriods()); $this->assertEquals(TimeSpan::asDuration(intval(floor($result->getDebtPeriodLengthInYears())), intval(floor($result->getDebtPeriodLengthInYears()) == 0 ? $result->getDebtPeriodLengthInMonths() : $result->getDebtPeriodLengthInMonths() % $result->getDebtPeriodLengthInYears()), intval(floor($result->getDebtPeriodLengthInMonths()) == 0 ? $result->getDebtPeriodLengthInDays() : $result->getDebtPeriodLengthInDays() % $result->getDebtPeriodLengthInMonths())), $result->getDebtPeriodLength()); $this->assertEquals(MathFuncs::div($result->getDebtPeriodLengthInDays(), TimeUtils::getDaysFromYears(1)), $result->getDebtPeriodLengthInYears()); $this->assertEquals(MathFuncs::div($result->getDebtPeriodLengthInDays(), TimeUtils::getDaysFromMonths(1)), $result->getDebtPeriodLengthInMonths()); $this->assertEquals(MathFuncs::div($result->getDebtLengthInDays(), TimeUtils::getDaysFromYears(1)), $result->getDebtLengthInYears()); $this->assertEquals(MathFuncs::div($result->getDebtLengthInDays(), TimeUtils::getDaysFromMonths(1)), $result->getDebtLengthInMonths()); $dateStart = new DateTime(); $dateEnd = clone $dateStart; $dateEnd->add(new DateInterval("P" . (int) $result->getDebtLengthInDays() . "D")); $this->assertEquals($dateEnd, $result->getDebtEndDate($dateStart)); $this->assertEquals("0.12", $result->getDebtInterest()); $repayments = $result->getDebtRepayments(); $INDIVIDUAL_REPAYMENT = "9729.03"; $this->assertEquals("4929.03", round($repayments[1]->getPrincipalAmount(), 2)); $this->assertEquals("4800.00", round($repayments[1]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[1]->getTotalAmount(), 2)); $this->assertEquals("5520.51", round($repayments[2]->getPrincipalAmount(), 2)); $this->assertEquals("4208.52", round($repayments[2]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[2]->getTotalAmount(), 2)); $this->assertEquals("6182.97", round($repayments[3]->getPrincipalAmount(), 2)); $this->assertEquals("3546.06", round($repayments[3]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[3]->getTotalAmount(), 2)); $this->assertEquals("6924.93", round($repayments[4]->getPrincipalAmount(), 2)); $this->assertEquals("2804.10", round($repayments[4]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[4]->getTotalAmount(), 2)); $this->assertEquals("7755.92", round($repayments[5]->getPrincipalAmount(), 2)); $this->assertEquals("1973.11", round($repayments[5]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[5]->getTotalAmount(), 2)); $this->assertEquals("8686.63", round($repayments[6]->getPrincipalAmount(), 2)); $this->assertEquals("1042.4", round($repayments[6]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[6]->getTotalAmount(), 2)); }
/** * @return string */ public function getTimeInDays() { return $this->time->toDays(); }
/** * @param $annuitySinglePaymentAmount * @param $annuityInterest * @return AnnuityCalculator */ public function newPerpetuity($annuitySinglePaymentAmount, $annuityInterest) { return $this->manufactureInstance([$annuitySinglePaymentAmount, 0, TimeSpan::asDuration(0), $annuityInterest]); }
/** * @return \FinanCalc\Calculators\AnnuityCalculator */ private function newAnnuityCalculatorDirectYearly() { return new AnnuityCalculator(100000, 5, TimeSpan::asDuration(1), 0.15); }
public function testCheckInstanceException() { $this->setExpectedException('InvalidArgumentException', ErrorMessages::getIncompatibleTypesMessage("Non\\Existing\\Class", "FinanCalc\\Calculators\\AnnuityCalculator")); Helpers::checkIfInstanceOfAClassOrThrowAnException(new AnnuityCalculator(100000, 5, TimeSpan::asDuration(1), 0.15), "Non\\Existing\\Class"); }
/** * @param DateTime $startDate [The start date of the debt] * @return DateTime [The end date of the debt] */ public function getDebtEndDate(DateTime $startDate) { return TimeSpan::asDurationWithStartDate($startDate, 0, 0, (int) $this->getDebtLengthInDays())->getEndDate(); }
public function testTimeSpanAsInterval() { $this->assertTimeSpan(TimeSpan::asInterval(new DateTime("2012-01-01"), new DateTime("2012-07-01"))); }
/** * @return SimpleInterestCalculator * @throws Exception */ private function newSimpleInterestCalculatorFactory() { return \FinanCalc\FinanCalc::getInstance()->getFactory('SimpleInterestCalculatorFactory')->newSimpleInterest(100, 0.0375, TimeSpan::asDuration(1)); }
/** * @return mixed * @throws Exception */ private function newSimpleDiscountCalculatorFactory() { return \FinanCalc\FinanCalc::getInstance()->getFactory('SimpleDiscountCalculatorFactory')->newSimpleDiscount(100000, 0.13, TimeSpan::asDuration(0, 6)); }
/** * @param $debtPrincipal * @param $debtNoOfPeriods * @param $debtInterest * @return DebtAmortizator */ public function newDailyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest) { return $this->manufactureInstance([$debtPrincipal, $debtNoOfPeriods, TimeSpan::asDuration(0, 0, 1), $debtInterest]); }
protected function setUp() { $this->timeSpan = TimeSpan::asDuration(1, 6, 90); parent::setUp(); }