<?

class PhpDate
{
	var $m_month;
	var $m_day;
	var $m_year;

	function PhpDate()
	{
		$this->SetFromTime( time() );
	}

	function SetMonth( $iMonth )
	{
		$this->m_month = $iMonth;
	}

	function SetDay( $iDay )
	{
		$this->m_day = $iDay;
	}

	function SetYear( $iYear )
	{
		$this->m_year = $iYear;
	}

	function CompileUnixTime()
	{
		return mktime( 0, 0, 0, $this->m_month - 1, $this->m_day, $this->m_year - 1900 );
	}

	function SetFromTime( $iTime )
	{
		// Break the time
		$tm = localtime ( $iTime, 1 );

		// Set components
		$this->m_month = $tm[ "tm_mon" ] + 1;
		$this->m_day = $tm[ "tm_mday" ];
		$this->m_year = $tm[ "tm_year" ] + 1900;
	}
};

function daysInMonth( $thisMonth, $thisYear ) {
	for( $thisDay = 1; checkdate( $thisMonth, $thisDay, $thisYear ); $thisDay++ );
	return $thisDay - 1;
}

function firstDayOfMonth( $thisMonth, $thisYear ) {
	return mktime(	1, 1, 1, $thisMonth, 1, $thisYear );
}

function lastDayOfMonth( $thisMonth, $thisYear ) {
	return mktime(	1, 1, 1, $thisMonth, daysInMonth($thisMonth, $thisYear), $thisYear );
}

function monthStartWeekDay( $thisMonth, $thisYear ) {
	return intval( strftime( "%w", firstDayOfMonth( $thisMonth, $thisYear ) ) );
}

function monthEndWeekDay( $thisMonth, $thisYear ) {
	return intval( strftime( "%w", lastDayOfMonth( $thisMonth, $thisYear ) ) );
}

function MakeDisplayTime( $sTime )
{
	// Return it if not correct format
	if( strlen( $sTime ) != 8 ) return $sTime;

	// Take it down
	$sTime = "1/1/2000 ".substr( $sTime, 0, 5 );

	// Crunch it
	$iTime = strtotime( $sTime );

	// Return a corrected version
	return strftime( "%I:%M %p", $iTime );
}

?>
