: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace NinjaForms\Includes\Handlers;
* Converts timestamps between formats, cognizant of WordPress settings
* This class is aware of the WordPress timezone settings and can convert
* stringed times into integer timestamps and vice-versa, relieving all other
* classes of this responsibility.
* Convert datetime string into epoch integer adjusted for WP timezone
* @param string $dateTime
public static function localizeDateTimeStringIntoEpoch(string $dateTimeString): int
$dateTimeString = '1970-01-01 00:00:00';
$timezone = self::getWpTimezoneSetting();
$dateTimeObject = new \DateTime( $dateTimeString, $timezone );
$return = $dateTimeObject->getTimestamp();
* Convert timestamp into local time adjusted for WP timezone
* @param integer $epochTimestamp
* @param string|null $format
public static function localizeEpochIntoString(int $epochTimestamp, ?string $format = 'Y-m-d H:i:s'): string
$timezone = self::getWpTimezoneSetting();
$dateTime = new \DateTime();
$dateTime->setTimezone($timezone);
$dateTime->setTimestamp($epochTimestamp);
$return = $dateTime->format($format);
* Returns the blog timezone
* Gets timezone settings from the db. If a timezone identifier is used just
* turns it into a DateTimeZone. If an offset is used, it tries to find a
* suitable timezone. If all else fails it uses UTC.
* https://wordpress.stackexchange.com/questions/198435/how-to-convert-datetime-to-display-time-based-on-wordpress-timezone-setting#198453
* @return \DateTimeZone The blog timezone
public static function getWpTimezoneSetting():\DateTimeZone
$timeZones = static::getWpTimezoneOptions();
$tzstring = $timeZones['timezone_string'];
$offset = $timeZones['gmt_offset'];
//@see http://us.php.net/manual/en/timezones.others.php
//@see https://bugs.php.net/bug.php?id=45543
//@see https://bugs.php.net/bug.php?id=45528
//IANA timezone database that provides PHP's timezone support uses POSIX (i.e. reversed) style signs
// Manual offset is disallowed; PHP 8.1.14, 8.2.1 will throw fatal error. Fallback to UTC. Let customers know that only timezone strings are allowed
//Issue with the timezone selected, set to 'UTC'
$timezone = new \DateTimeZone($tzstring);
* Returns stored WP options values for timezone_string, gmt_offset
protected static function getWpTimezoneOptions( ): array
'timezone_string' => \get_option('timezone_string'),
'gmt_offset' => \get_option('gmt_offset')