Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculating periods created is wrong with a subscription phase with an end date #187

Open
remcotolsma opened this issue Jun 19, 2024 · 1 comment

Comments

@remcotolsma
Copy link
Member

remcotolsma commented Jun 19, 2024

/**
* Get periods created.
*
* @return int
*/
public function get_periods_created() {
$next_date = $this->subscription->get_next_payment_date();
if ( null === $next_date ) {
return 0;
}
$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' ) )
);
return \iterator_count( $period );
}

The next payment date can go far beyond the end date of a subscription phase.

Scherm­afbeelding 2024-06-19 om 12 25 03

Should we add something like this?

if ( null !== $this->end_date ) {
	$next_date = \min( $next_date, $this->end_date );
}

Probably also rename the variable $next_date to $anchor_date or $pointer_date?

CC @rvdsteege

@rvdsteege
Copy link
Member

Should we add something like this?

As discussed at HQ, I think that that would be correct to fix the calculation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

2 participants