27 lines
900 B
PHP
27 lines
900 B
PHP
<?php
|
|
|
|
function endOfSubscriptionIsNear1(
|
|
DateTime $today,
|
|
DateTime $endOfSubscription
|
|
) {
|
|
return $endOfSubscription < $today->modify('+15 days');
|
|
}
|
|
|
|
function endOfSubscriptionIsNear2(
|
|
DateTime $endOfSubscription
|
|
) {
|
|
return $endOfSubscription < (new DateTime)->modify('+15 days');
|
|
}
|
|
|
|
$closedEndOfSubscription = (new DateTime)->modify('+14 days');
|
|
$farEndOfSubscription = (new DateTime)->modify('+16 days');
|
|
|
|
vprintf("Using new object should be 1: %d\n", endOfSubscriptionIsNear1(new DateTime, $closedEndOfSubscription));
|
|
vprintf("Using new object should be 0: %d\n", endOfSubscriptionIsNear1(new DateTime, $farEndOfSubscription));
|
|
|
|
$today = new DateTime;
|
|
$endOfSubscription = (new DateTime)->modify('+16 days');
|
|
|
|
vprintf("First call: %d\n", endOfSubscriptionIsNear1($today, $endOfSubscription));
|
|
vprintf("Second call: %d\n", endOfSubscriptionIsNear1($today, $endOfSubscription));
|