Automattic\WooCommerce\Internal\TransientFiles

TransientFilesEngine::get_expiration_date()public staticWC 1.0

Get the expiration date of a transient file based on its file name. The actual existence of the file is NOT checked.

Method of the class: TransientFilesEngine{}

No Hooks.

Return

String|null. Expiration date formatted as Y-m-d, null if the file name isn't encoding a proper date.

Usage

$result = TransientFilesEngine::get_expiration_date( $filename ) : ?string;
$filename(string) (required)
The name of the transient file to get the expiration date for.

TransientFilesEngine::get_expiration_date() code WC 9.5.1

public static function get_expiration_date( string $filename ) : ?string {
	if ( strlen( $filename ) < 7 || ! ctype_xdigit( $filename ) ) {
		return null;
	}

	$expiration_date = sprintf(
		'%04d-%02d-%02d',
		hexdec( substr( $filename, 0, 3 ) ),
		hexdec( substr( $filename, 3, 1 ) ),
		hexdec( substr( $filename, 4, 2 ) )
	);

	return TimeUtil::is_valid_date( $expiration_date, 'Y-m-d' ) ? $expiration_date : null;
}