diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-03-14 20:53:33 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-03-14 20:53:33 -0400 |
commit | 253996901a10918e3207d46839cdfdc90d200e72 (patch) | |
tree | 5e359471d8e7de963277c37c6ff9611181505975 /app/Model/DateParser.php | |
parent | 4700139a86d1ef44eabe43edb5a4abff9c645811 (diff) |
Calculate the time spent based on the timetable
Diffstat (limited to 'app/Model/DateParser.php')
-rw-r--r-- | app/Model/DateParser.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/app/Model/DateParser.php b/app/Model/DateParser.php index 8a4d3edd..a0d10a36 100644 --- a/app/Model/DateParser.php +++ b/app/Model/DateParser.php @@ -13,6 +13,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 * * @access public |