Skip to content

Commit

Permalink
tweak(TB test issues) date time test failes fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmhh committed Dec 30, 2024
1 parent 04b1a05 commit 44b0caf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Tinebase_Helper_Algorithm_TerminationDeadlineTest extends TestCase
*/
public function testGetTerminationDeadline()
{
$commencement = new Tinebase_DateTime(date('Y-m-d', strtotime('first day of January this year')));
$commencement = new Tinebase_DateTime(date('Y-01-01'));
$termOfContractInMonths = 12;
$automaticContractExtensionInMonths = 12;
$cancelationPeriodInMonths = 3;
Expand All @@ -30,7 +30,7 @@ public function testGetTerminationDeadline()
$termOfContractInMonths,
$automaticContractExtensionInMonths,
$cancelationPeriodInMonths,
(new Tinebase_DateTime())->setWeek(50)->setWeekDay(1)
new Tinebase_DateTime(date('Y-12-30'))
);

$expectedTerminationDeadline = (clone $commencement)->addYear(2)->subMonth($cancelationPeriodInMonths)->subDay(1);
Expand All @@ -39,7 +39,7 @@ public function testGetTerminationDeadline()

public function testGetTerminationDeadlineWithSixMonthExtension()
{
$commencement = new Tinebase_DateTime(date('Y-m-d', strtotime('first day of January this year')));
$commencement = new Tinebase_DateTime(date('Y-01-01'));
$termOfContractInMonths = 12;
$automaticContractExtensionInMonths = 6;
$cancelationPeriodInMonths = 3;
Expand All @@ -49,7 +49,7 @@ public function testGetTerminationDeadlineWithSixMonthExtension()
$termOfContractInMonths,
$automaticContractExtensionInMonths,
$cancelationPeriodInMonths,
(new Tinebase_DateTime())->setWeek(50)->setWeekDay(1)
new Tinebase_DateTime(date('Y-12-30'))
);

$expectedTerminationDeadline = (clone $commencement)->addYear(1)->addMonth($automaticContractExtensionInMonths)->subMonth($cancelationPeriodInMonths)->subDay(1);
Expand All @@ -61,7 +61,7 @@ public function testGetTerminationDeadlineWithSixMonthExtension()
*/
public function testGetTerminationDeadlineForExtendedContract()
{
$commencement = (new Tinebase_DateTime())->setWeek(1)->setWeekDay(1)->subYear(2);
$commencement = (new Tinebase_DateTime(date('Y-01-01')))->subYear(2);
$termOfContractInMonths = 12;
$automaticContractExtensionInMonths = 12;
$cancelationPeriodInMonths = 3;
Expand All @@ -71,7 +71,7 @@ public function testGetTerminationDeadlineForExtendedContract()
$termOfContractInMonths,
$automaticContractExtensionInMonths,
$cancelationPeriodInMonths,
(new Tinebase_DateTime())->setWeek(50)->setWeekDay(1)
new Tinebase_DateTime(date('Y-12-30'))
);

$expectedTerminationDeadline = (clone $commencement)->addYear(4)->subMonth($cancelationPeriodInMonths)->subDay(1);
Expand Down
12 changes: 3 additions & 9 deletions tine20/Tinebase/Helper/Algorithm/TerminationDeadline.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,13 @@ public function getTerminationDeadline(
$cancelationPeriodInMonths,
$today = null
) {
$today = $today ?: Tinebase_DateTime::now();
$today = $today ?: Tinebase_DateTime::today();

// Without renewal consideration
$contractEndDate = (clone $commencement)->addMonth($termOfContractInMonths);

// Calculate end date including renewals
$commencementCopy = clone $commencement;
for (
$commencementCopy->addMonth($termOfContractInMonths);
(clone $commencementCopy)->subMonth($cancelationPeriodInMonths) < $today;
$commencementCopy->addMonth($automaticContractExtensionInMonths)
) {
$contractEndDate = $commencementCopy;
while ($contractEndDate->getClone()->subMonth($cancelationPeriodInMonths)->subDay(1) < $today) {
$contractEndDate->addMonth($automaticContractExtensionInMonths);
}

return $contractEndDate->subMonth($cancelationPeriodInMonths)->subDay(1);
Expand Down

0 comments on commit 44b0caf

Please sign in to comment.