summaryrefslogtreecommitdiff
path: root/app/Model/DateParser.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model/DateParser.php')
-rw-r--r--app/Model/DateParser.php41
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