1 #include "lib/format.hpp"
2 
3 using namespace lib;
4 
time(int ms)5 std::string fmt::time(int ms)
6 {
7 	auto seconds = ms / 1000;
8 
9 	auto m = seconds / 60;
10 	auto s = seconds % 60;
11 
12 	return format("{}:{}", m,
13 		format("{}{}", s < 10 ? "0" : "", s % 60));
14 }
15 
size(unsigned int bytes)16 std::string fmt::size(unsigned int bytes)
17 {
18 	if (bytes >= 1000000000)
19 		return format("{} GB", bytes / 1000000000);
20 
21 	if (bytes >= 1000000)
22 		return format("{} MB", bytes / 1000000);
23 
24 	if (bytes >= 1000)
25 		return format("{} kB", bytes / 1000);
26 
27 	return format("{} B", bytes);
28 }
29 
count(unsigned int count)30 auto fmt::count(unsigned int count) -> std::string
31 {
32 	if (count >= 1000000)
33 	{
34 		return format("{}M", count / 1000000);
35 	}
36 
37 	if (count >= 1000)
38 	{
39 		return format("{}k", count / 1000);
40 	}
41 
42 	return format("{}", count);
43 }
44