<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Date_info extends CI_Controller {
	function today_is(){
		date_default_timezone_set("Asia/Jakarta");
		echo json_encode(array('st'=>1,'date'=>date("Y-m-d",time())));
	}

	function time_is(){
		date_default_timezone_set("Asia/Jakarta");
		echo json_encode(array('st'=>1,'date'=>date("h:i:s",time())));
	}

	function datetime_is(){
		date_default_timezone_set("Asia/Jakarta");
		echo json_encode(array('st'=>1,'date'=>date("Y-m-d h:i:s",time())));
	}


	function date_different(){
		if(empty($_POST)){
			echo json_encode(array('st'=>0,'diff'=>'Error'));
			return;
		}
		date_default_timezone_set("Asia/Jakarta");
		$begin = new DateTime($this->input->post('now',TRUE));
		$end = new DateTime($this->input->post('date',TRUE));
		$diff = $begin->diff($end);
		if($diff->format('%R%a')<0){
			$status = 'past';
		}else{
			$status = 'future';
		}
		echo json_encode(array('st'=>$status,'diff'=>$diff->format('%R%a')));
	}
}