Basically, does it work? Thoughts, ideas, or comments welcome.
Code: Select all
<?php
if ( !defined('ECLIPSE_TIMEPOINT') ) {
define('ECLIPSE_TIMEPOINT', '');
/**
* TimePoint
* Handles time points
*
* @package EclipseValues
*/
class TimePoint
{
var $seconds;
var $minutes;
var $hours;
var $month_day;
var $weekday_number;
var $month_number;
var $year;
var $year_day;
var $weekday_name;
var $month_name;
var $timestamp;
/**
* @description Handles time points
*/
function TimePoint ( $timestamp=false )
{
$this->_now($timestamp);
}
/**
* addYears
* @desc Add a number of years to the time
* @access private
* @param int $years
* @return TimePoint
*/
function addYears ( $years )
{
return new TimePoint(mktime($this->hours,
$this->minutes,
$this->seconds,
$this->month_number,
$this->month_day,
$this->year + $years));
}
/**
* minusYears
* @desc Subtract a number of years from the time
* @access private
* @param int $years
* @return TimePoint
*/
function minusYears ( $years )
{
return $this->addYears(-$years);
}
/**
* addMonths
* @desc Add a number of months to the time
* @access public
* @param int $months
* @return TimePoint
*/
function addMonths ( $months )
{
return new TimePoint(mktime($this->hours,
$this->minutes,
$this->seconds,
$this->month_number + $months,
$this->month_day,
$this->year));
}
/**
* minusMonths
* @desc Subtract a number of months from the time
* @access public
* @param int $months
* @return TimePoint
*/
function minusMonths ( $months )
{
return $this->addMonths(-$months);
}
/**
* addDays
* @desc Add a number of days to the time
* @access public
* @param int $days
* @return TimePoint
*/
function addDays ( $days )
{
return new TimePoint(mktime($this->hours,
$this->minutes,
$this->seconds,
$this->month_number,
$this->month_day + $days,
$this->year));
}
/**
* minusDays
* @desc Subtract a number of days from the time
* @access public
* @param int $days
* @return TimePoint
*/
function minusDays ( $days )
{
return $this->addDays(-$days);
}
/**
* isAfter
* @desc Whether the object is after the passed TimePoint
* @access public
* @param TimePoint $TimePoint
* @return bool
*/
function isAfter ( $TimePoint )
{
return ($this->timestamp > $TimePoint->get_timestamp());
}
/**
* isBefore
* @desc Whether the object is before the passed TimePoint
* @access public
* @param TimePoint $TimePoint
* @return bool
*/
function isBefore ( $TimePoint )
{
return ($this->timestamp < $TimePoint->get_timestamp());
}
/**
* isEqualTime
* @desc Whether the two TimePoints are equal to the second
* @access public
* @param TimePoint $TimePoint
* @return bool
*/
function isEqualTime ( $TimePoint )
{
return ($this->timestamp == $TimePoint->get_timestamp());
}
/**
* isSameDay
* @desc Whether the two TimePoints occured on the same day
* @access public
* @param TimePoint $TimePoint
* @return bool
*/
function isSameDay ( &$TimePoint )
{
$Date1 =& $this->trimToDays();
$Date2 =& $TimePoint->trimToDays();
return ($Date1->get_timestamp() == $Date2->get_timestamp());
}
/**
* trimToDays
* @desc Set's the precision to day
* @access public
* @return void
*/
function &trimToDays ()
{
return new TimePoint(mktime(0, 0, 0,
$this->month_number,
$this->month_day,
$this->year));
}
/**
* _resetTime
* @desc Whenever something is set, we need to reset the time
* @access private
* @return void
*/
function _resetTime ()
{
$this->_now(mktime($this->hours,
$this->minutes,
$this->seconds,
$this->month_number,
$this->month_day,
$this->year));
}
/**
* now
* @desc Returns a Date for the current date
* @access public
* @return TimePoint
*/
function now ()
{
return new TimePoint();
}
/**
* _now
* @desc Set's the value to the current date
* @access private
* @return void
*/
function _now ( $timestamp=false)
{
$stamp = $timestamp ? $timestamp : time();
$date = getdate($stamp);
$this->seconds = $date['seconds'];
$this->minutes = $date['minutes'];
$this->hours = $date['hours'];
$this->month_day = $date['mday'];
$this->weekday_number = $date['wday'];
$this->month_number = $date['mon'];
$this->year = $date['year'];
$this->year_day = $date['yday'];
$this->weekday_name = $date['weekday'];
$this->month_name = $date['month'];
$this->timestamp = $date['0'];
}
/**
* @desc Setter for seconds
* @access public
* @return void
* @param int seconds
*/
function set_seconds ( $seconds ) {
$this->seconds = $seconds;
$this->_resetTime();
}
/**
* @desc Setter for minutes
* @access public
* @return void
* @param int minutes
*/
function set_minutes ( $minutes ) {
$this->minutes = $minutes;
$this->_resetTime();
}
/**
* @desc Setter for hours
* @access public
* @return void
* @param int hours
*/
function set_hours ( $hours ) {
$this->hours = $hours;
$this->_resetTime();
}
/**
* @desc Setter for month_day
* @access public
* @return void
* @param int month_day
*/
function set_month_day ( $month_day ) {
$this->month_day = $month_day;
$this->_resetTime();
}
/**
* @desc Setter for weekday_number
* @access public
* @return void
* @param int weekday_number
*/
function set_weekday_number ( $weekday_number ) {
$this->weekday_number = $weekday_number;
$this->_resetTime();
}
/**
* @desc Setter for month_number
* @access public
* @return void
* @param int month_number
*/
function set_month_number ( $month_number ) {
$this->month_number = $month_number;
$this->_resetTime();
}
/**
* @desc Setter for year
* @access public
* @return void
* @param int year
*/
function set_year ( $year ) {
$this->year = $year;
$this->_resetTime();
}
/**
* @desc Setter for year_day
* @access public
* @return void
* @param int year_day
*/
function set_year_day ( $year_day ) {
$this->year_day = $year_day;
$this->_resetTime();
}
/**
* @desc Setter for timestamp
* @access public
* @return void
* @param int timestamp
*/
function set_timestamp ( $timestamp ) {
$this->timestamp = $timestamp;
$this->_resetTime();
}
/**
* @desc Getter for seconds
* @access public
* @return int
*/
function get_seconds () { return $this->seconds; }
/**
* @desc Getter for minutes
* @access public
* @return int
*/
function get_minutes () { return $this->minutes; }
/**
* @desc Getter for hours
* @access public
* @return int
*/
function get_hours () { return $this->hours; }
/**
* @desc Getter for month_day
* @access public
* @return int
*/
function get_month_day () { return $this->month_day; }
/**
* @desc Getter for weekday_number
* @access public
* @return int
*/
function get_weekday_number () { return $this->weekday_number; }
/**
* @desc Getter for month_number
* @access public
* @return int
*/
function get_month_number () { return $this->month_number; }
/**
* @desc Getter for year
* @access public
* @return int
*/
function get_year () { return $this->year; }
/**
* @desc Getter for year_day
* @access public
* @return int
*/
function get_year_day () { return $this->year_day; }
/**
* @desc Getter for weekday_name
* @access public
* @return string
*/
function get_weekday_name () { return $this->weekday_name; }
/**
* @desc Getter for month_name
* @access public
* @return string
*/
function get_month_name () { return $this->month_name; }
/**
* @desc Getter for timestamp
* @access public
* @return int
*/
function get_timestamp () { return $this->timestamp; }
}
}
?>