Skip to content

Commit

Permalink
✨ add size() method for human readable sizes
Browse files Browse the repository at this point in the history
Signed-off-by: otengkwame <[email protected]>
  • Loading branch information
otengkwame committed Nov 26, 2022
1 parent c0dd863 commit 620265b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Core/core/Helpers/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ public function fixDatetime($datetime)
return correct_datetime($datetime);
}

/**
* Get human readable size
*
* @param integer|float $bytes
* @return string
*/
public function size(int|float $bytes)
{
$i = floor( log($bytes, 1024) );

return round(
$bytes / pow(1024, $i),
[0,0,2,2,3,3,3,3,3][$i]
) . ['B','kB','MB','GB','TB','PB','EB','ZB','YB'][$i];
}

// FORMATTING OUTPUT ---------------------------------------------------------

/**
Expand Down

0 comments on commit 620265b

Please sign in to comment.