<?php
defined('VSIGN') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");

class DateManager
{
	private $db;
	
	public function __construct(database $db)
	{
		$this->db 	=& $db;
	}
	
	public function GetClock()
	{
		return date("H:i T");
	}
	
	public function GetSystemClock()
	{
		return gmdate("H:i T");
	}
	
	public function GetLocalDate($format = 'Y-m-d H:i:s', $timestamp = '')
	{
		$db	=& $this->db;
		
		if ($timestamp == '')
		{
			$timestamp = time();
		}
		
		Debug::LogEntry($db, 'audit', 'Converting ' . $timestamp . ' to a Local Date');
		
		return date($format, $timestamp);
	}
	
	public function GetSystemDate($format = 'Y-m-d H:i:s', $timestamp = '')
	{
		$db	=& $this->db;
				
		if ($timestamp == '')
		{
			$timestamp = time();
		}
		
		Debug::LogEntry($db, 'audit', 'Converting ' . $timestamp . ' to a System Date');
		
		return gmdate($format, $timestamp);
	}

        /**
         * Gets an ISO date from a US formatted date string
         * @param <string> $usDate
         * @param <string> $time
         */
        public function GetDateFromUS($usDate, $time)
        {
            // Split the US date by /
            $datePart = explode('/', $usDate);

            return (int) strtotime($datePart[2] . '-' . $datePart[1] . '-' . $datePart[0] . ' ' . $time);
        }
} 
?>