HEX
Server: Apache/2
System: Linux vpslll9m.sdns.vn 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
User: thuexe247c (1044)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/thuexe247c/public_html/wp-content/plugins/date-counter/Classes/DatetimeDifference.php
<?php


class DatetimeDifference extends AbstractDatetime
{
	public function display($atts)
	{
		if (!isset($atts["startdate"]))
			return self::error_message('<b>startDate</b> attribute is required.');

		if (!isset($atts["enddate"]))
			return self::error_message('<b>endDate</b> attribute is required.');

		if (!isset($atts["format"]))
			return self::error_message('<b>format</b> attribute is required.');

		try {
			$start_date = $this->get_datetime($atts["startdate"]);
			$end_date = $this->get_datetime($atts["enddate"]);

			$difference = $end_date->diff($start_date);

			$response = $difference->format(self::normalize_format($atts['format']));

		} catch (Exception $e) {
			$response = self::error_message($e->getMessage());
		} finally {
			return $response;
		}
	}

	protected static function normalize_format($format) {
		$symbols = ['Y', 'y', 'M', 'm', 'D', 'd', 'a', 'H', 'h', 'I', 'i', 'S', 's', 'F', 'f', 'R', 'r'];

		foreach ($symbols as $symbol) {
			$format = preg_replace("/(\b$symbol{1}\b)/", "%$symbol", $format);
		}

		return $format;
	}
}

add_shortcode( 'DatetimeDifference', array( new DatetimeDifference, 'display') );