TimeDiffHelper.php 666 B

12345678910111213141516171819
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\helpers;
  3. class TimeDiffHelper {
  4. public static function getExtendedDataInterval(\DateInterval $diff) {
  5. $diff->years = floor($diff->days / 365.25);
  6. $diff->months = floor($diff->days / 30);
  7. $diff->hours = $diff->days * 24 + $diff->h;
  8. $diff->minutes = $diff->hours * 60 + $diff->i;
  9. $diff->seconds = $diff->minutes * 60 + $diff->s;
  10. return $diff;
  11. }
  12. public static function diff($date1, $date2 = '') {
  13. $date1 = new \DateTime($date1);
  14. return self::getExtendedDataInterval($date1->diff(new \DateTime($date2)));
  15. }
  16. }