woocommerce-paypal-payments/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php

43 lines
788 B
PHP
Raw Normal View History

2022-05-10 10:25:06 +02:00
<?php
/**
* Helper methods for PUI.
*
* @package WooCommerce\PayPalCommerce\WcGateway\Helper
*/
declare( strict_types=1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
2022-05-10 11:59:24 +02:00
use DateTime;
2022-05-10 10:25:06 +02:00
2022-05-10 11:59:24 +02:00
/**
* Class PayUponInvoiceHelper
*/
class PayUponInvoiceHelper {
/**
* Ensures date is valid and at least 18 years back.
*
* @param string $date The date.
* @param string $format The date format.
* @return bool
*/
public function validate_birth_date( string $date, string $format = 'Y-m-d' ): bool {
$d = DateTime::createFromFormat( $format, $date );
if ( false === $d ) {
return false;
}
if ( $date !== $d->format( $format ) ) {
return false;
}
if ( time() < strtotime( '+18 years', strtotime( $date ) ) ) {
return false;
}
return true;
}
2022-05-10 10:25:06 +02:00
}