Format.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Sep 13, 2018)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\ProxmoxAddon\App\Libs;
  20. /**
  21. * Description of Format
  22. *
  23. * @author Pawel Kopec <pawelk@modulesgardne.com>
  24. */
  25. class Format
  26. {
  27. /**
  28. * FUNCTION convert
  29. * Format bytes
  30. * @param int $bytes
  31. * @param int $precision
  32. * @return string
  33. */
  34. public static function convertBytes($bytes, $precision = 2)
  35. {
  36. $units = ['B', 'KB', 'MB', 'GB', 'TB'];
  37. $bytes = max($bytes, 0);
  38. $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
  39. $pow = min($pow, count($units) - 1);
  40. $bytes /= (1 << (10 * $pow));
  41. return round($bytes, $precision) . ' ' . $units[$pow];
  42. }
  43. public static function uptime($uptime)
  44. {
  45. if (!$uptime)
  46. {
  47. return false;
  48. }
  49. $days = floor($uptime / 60 / 60 / 24);
  50. $hours = $uptime / 60 / 60 % 24;
  51. $mins = $uptime / 60 % 60;
  52. $secs = $uptime % 60;
  53. $hours = ($hours < 10) ? "0" . $hours : $hours;
  54. $mins = ($mins < 10) ? "0" . $mins : $mins;
  55. $secs = ($secs < 10) ? "0" . $secs : $secs;
  56. if ($days)
  57. {
  58. return "{$days} days $hours:$mins:$secs";
  59. }
  60. else
  61. {
  62. return "$hours:$mins:$secs";
  63. }
  64. }
  65. }