ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Formatter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
28trait Formatter
29{
30 protected function formatSize(int $size): string
31 {
32 $size_factor = 1000;
33 $unit = match (true) {
34 $size > $size_factor * $size_factor * $size_factor => DataSize::GB,
35 $size > $size_factor * $size_factor => DataSize::MB,
36 $size > $size_factor => DataSize::KB,
37 default => DataSize::Byte,
38 };
39
40 $size = (int) (round((float) $size / (float) $unit, 2) * (float) $unit);
41
42 return (string) (new DataSize($size, $unit));
43 }
44
45 protected function formatDate(\DateTimeImmutable $date): string
46 {
47 return $date->format('Y-m-d H:i');
48 }
49}
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31