Skip to content

Commit

Permalink
Merge pull request #192 from pronamic/191-number-of-periods-created-f…
Browse files Browse the repository at this point in the history
…or-subscription-phase-should-not-count-outside-of-an-optional-phase-end-date

Fix calculated number of periods created falling outside optional phase end date.
  • Loading branch information
rvdsteege authored Jul 31, 2024
2 parents cc89c29 + e74fce6 commit 0364e4f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Subscriptions/SubscriptionPhase.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,22 @@ public function set_total_periods( $total_periods ) {
* @return int
*/
public function get_periods_created() {
$next_date = $this->subscription->get_next_payment_date();
$next_payment_date = $this->subscription->get_next_payment_date();

if ( null === $next_date ) {
$end_date = $next_payment_date ?? $this->end_date;

if ( null === $end_date ) {
return 0;
}

if ( null !== $this->end_date && $end_date > $this->end_date ) {
$end_date = $this->end_date;
}

$period = new \DatePeriod(
new \DateTimeImmutable( $this->start_date->format( 'Y-m-d 00:00:00' ) ),
$this->interval,
new \DateTimeImmutable( $next_date->format( 'Y-m-d 00:00:00' ) )
new \DateTimeImmutable( $end_date->format( 'Y-m-d 00:00:00' ) )
);

return \iterator_count( $period );
Expand Down

0 comments on commit 0364e4f

Please sign in to comment.