Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/helpers
File: date-helper.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Helpers;
[2] Fix | Delete
[3] Fix | Delete
use DateTime;
[4] Fix | Delete
use DateTimeZone;
[5] Fix | Delete
use Exception;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* A helper object for dates.
[9] Fix | Delete
*/
[10] Fix | Delete
class Date_Helper {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Convert given date string to the W3C format.
[14] Fix | Delete
*
[15] Fix | Delete
* If $translate is true then the given date and format string will
[16] Fix | Delete
* be passed to date_i18n() for translation.
[17] Fix | Delete
*
[18] Fix | Delete
* @param string $date Date string to convert.
[19] Fix | Delete
* @param bool $translate Whether the return date should be translated. Default false.
[20] Fix | Delete
*
[21] Fix | Delete
* @return string Formatted date string.
[22] Fix | Delete
*/
[23] Fix | Delete
public function mysql_date_to_w3c_format( $date, $translate = false ) {
[24] Fix | Delete
return \mysql2date( \DATE_W3C, $date, $translate );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Formats a given date in UTC TimeZone format.
[29] Fix | Delete
*
[30] Fix | Delete
* @param string $date String representing the date / time.
[31] Fix | Delete
* @param string $format The format that the passed date should be in.
[32] Fix | Delete
*
[33] Fix | Delete
* @return string The formatted date.
[34] Fix | Delete
*/
[35] Fix | Delete
public function format( $date, $format = \DATE_W3C ) {
[36] Fix | Delete
if ( ! \is_string( $date ) ) {
[37] Fix | Delete
return $date;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
$immutable_date = \date_create_immutable_from_format( 'Y-m-d H:i:s', $date, new DateTimeZone( 'UTC' ) );
[41] Fix | Delete
[42] Fix | Delete
if ( ! $immutable_date ) {
[43] Fix | Delete
return $date;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
return $immutable_date->format( $format );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Formats the given timestamp to the needed format.
[51] Fix | Delete
*
[52] Fix | Delete
* @param int $timestamp The timestamp to use for the formatting.
[53] Fix | Delete
* @param string $format The format that the passed date should be in.
[54] Fix | Delete
*
[55] Fix | Delete
* @return string The formatted date.
[56] Fix | Delete
*/
[57] Fix | Delete
public function format_timestamp( $timestamp, $format = \DATE_W3C ) {
[58] Fix | Delete
if ( ! \is_string( $timestamp ) && ! \is_int( $timestamp ) ) {
[59] Fix | Delete
return $timestamp;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
$immutable_date = \date_create_immutable_from_format( 'U', $timestamp, new DateTimeZone( 'UTC' ) );
[63] Fix | Delete
[64] Fix | Delete
if ( ! $immutable_date ) {
[65] Fix | Delete
return $timestamp;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
return $immutable_date->format( $format );
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Formats a given date in UTC TimeZone format and translate it to the set language.
[73] Fix | Delete
*
[74] Fix | Delete
* @param string $date String representing the date / time.
[75] Fix | Delete
* @param string $format The format that the passed date should be in.
[76] Fix | Delete
*
[77] Fix | Delete
* @return string The formatted and translated date.
[78] Fix | Delete
*/
[79] Fix | Delete
public function format_translated( $date, $format = \DATE_W3C ) {
[80] Fix | Delete
return \date_i18n( $format, $this->format( $date, 'U' ) );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
[85] Fix | Delete
*
[86] Fix | Delete
* @return int The current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
[87] Fix | Delete
*/
[88] Fix | Delete
public function current_time() {
[89] Fix | Delete
return \time();
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
/**
[93] Fix | Delete
* Check if a string is a valid datetime.
[94] Fix | Delete
*
[95] Fix | Delete
* @param string $datetime String input to check as valid input for DateTime class.
[96] Fix | Delete
*
[97] Fix | Delete
* @return bool True when datetime is valid.
[98] Fix | Delete
*/
[99] Fix | Delete
public function is_valid_datetime( $datetime ) {
[100] Fix | Delete
if ( $datetime === null ) {
[101] Fix | Delete
/*
[102] Fix | Delete
* While not "officially" supported, `null` will be handled as `"now"` until PHP 9.0.
[103] Fix | Delete
* @link https://3v4l.org/tYp2k
[104] Fix | Delete
*/
[105] Fix | Delete
return true;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
if ( \is_string( $datetime ) && \substr( $datetime, 0, 1 ) === '-' ) {
[109] Fix | Delete
return false;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
try {
[113] Fix | Delete
return new DateTime( $datetime ) !== false;
[114] Fix | Delete
} catch ( Exception $exception ) {
[115] Fix | Delete
return false;
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function