<?php  
namespace WCQT\classes\com;

class Time
{
	public function _construct()
	{
		
	}
	public function get_specific_dates_to_disable($data)
	{
		$options = isset($data) ? $data : "";
		$options = $options == "" && isset($data) ? $data:$options;
		$options = trim($options);
		
		$options = $options != "" ? explode(PHP_EOL, $options) : array();
		
		if(empty($options))
			return $options;
		
		try{
			$day_and_month = array(); 
			foreach((array)$options as $option)
			{
				$tmp_result = explode(":", $option);
				$day_and_month[] = date('Y').",".(trim($tmp_result[1])-1).",".trim($tmp_result[0]); //year,month, day
				$day_and_month[] = date("Y",strtotime("-1 year")).",".(trim($tmp_result[1])-1).",".trim($tmp_result[0]); //previous year
				$day_and_month[] = date("Y",strtotime("+1 year")).",".(trim($tmp_result[1])-1).",".trim($tmp_result[0]); //next year
			}
		}catch(Exception  $e){return array();}
		
		return $day_and_month;
		
	}
	public function get_time_according_wordprerss_settings($time)
	{
		if($time == "" || !isset($time))
			return "";
		
		try{
			$date = new \DateTime($time);
		}
		catch(Exception $e)
		{
			return $datetime;
		}
		return $date->format(get_option('time_format'));
	}
	public function get_date_according_wordprerss_settings($date)
	{
		if($date == "" || !isset($date))
			return "";
		
		try
		{
			$date = new \DateTime($date);
		}
		catch(Exception $e)
		{
			return $datetime;
		}
		return $date->format(get_option('date_format'));
	}
	public function get_date_time_according_wordpress_settings($datetime)
	{
		if($datetime == "" || !isset($datetime))
			return "";
		
		try
		{
			$date = new \DateTime($datetime);
		}
		catch(Exception $e)
		{
			return $datetime;
		}
		return $date->format(get_option('date_format')." ".get_option('time_format'));
	}
	public function add_time_to_time($datetime, $to_add)
	{
		return date('Y-m-d H:i:s', strtotime($datetime. ' + '.$to_add));
	}
	public function add_time_to_now($to_add)
	{
		$now = current_time('mysql');
		return date('Y-m-d H:i:s', strtotime($now. ' + '.$to_add));
	}
	public function now()
	{
		return current_time('mysql');
	}
}
?>