Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Dejan Marjanovic <dejan.marjanovic@gmail.com>
- * @package eng5
- * @name Webarto DateTime
- */
- class WA_DT
- {
- /**
- * Calculate shift span in one calendar day, if shift crosses midnight
- *
- * @return array
- */
- public static function shift_span($start, $end)
- {
- $time_diff = self::time_diff($start, $end);
- $time_diff = $time_diff['hours'];
- # ignore minutes, safe after we calculated difference
- $start = (int) $start;
- $end = (int) $end;
- if($start + $time_diff < 24)
- return array($time_diff);
- return array(
- abs($end - $time_diff),
- abs(($start + $time_diff) % 24)
- );
- }
- /**
- * Calculate shift span in hours (sort of TIMEDIFF MySQL)
- *
- * @return array
- */
- public static function time_diff($start, $end)
- {
- # do not ignore minutes
- $start = strtotime($start);
- $end = strtotime($end);
- $diff = abs($start - $end);
- $hours = floor($diff / 3600);
- $minutes = ($diff - ($hours * 3600)) / 60;
- $hours = $start > $end? 24 - $hours: $hours;
- return compact('hours', 'minutes');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement