Calculate the time spent based on the timetable
This commit is contained in:
@@ -12,6 +12,47 @@ use DateTime;
|
||||
*/
|
||||
class DateParser extends Base
|
||||
{
|
||||
/**
|
||||
* Return true if the date is within the date range
|
||||
*
|
||||
* @access public
|
||||
* @param DateTime $date
|
||||
* @param DateTime $start
|
||||
* @param DateTime $end
|
||||
* @return boolean
|
||||
*/
|
||||
public function withinDateRange(DateTime $date, DateTime $start, DateTime $end)
|
||||
{
|
||||
return $date >= $start && $date <= $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of hours between 2 datetime objects
|
||||
* Minutes are rounded to the nearest quarter
|
||||
*
|
||||
* @access public
|
||||
* @param DateTime $d1
|
||||
* @param DateTime $d2
|
||||
* @return float
|
||||
*/
|
||||
public function getHours(DateTime $d1, DateTime $d2)
|
||||
{
|
||||
$seconds = $this->getRoundedSeconds(abs($d1->getTimestamp() - $d2->getTimestamp()));
|
||||
return round($seconds / 3600, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Round the timestamp to the nearest quarter
|
||||
*
|
||||
* @access public
|
||||
* @param integer $seconds Timestamp
|
||||
* @return integer
|
||||
*/
|
||||
public function getRoundedSeconds($seconds)
|
||||
{
|
||||
return (int) round($seconds / (15 * 60)) * (15 * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a timestamp if the given date format is correct otherwise return 0
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user