mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
AK: Add human_readable_digital_time() helper
Converts seconds into a readable digital format. For example: 30 seconds = "00:30" 90 seconds = "01:30" 86401 seconds = "24:00:01" And so on.
This commit is contained in:
parent
a808cfa75c
commit
75b6097c55
1 changed files with 19 additions and 0 deletions
|
@ -63,8 +63,27 @@ static inline String human_readable_time(i64 time_in_seconds)
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline String human_readable_digital_time(i64 time_in_seconds)
|
||||||
|
{
|
||||||
|
auto hours = time_in_seconds / 3600;
|
||||||
|
time_in_seconds = time_in_seconds % 3600;
|
||||||
|
|
||||||
|
auto minutes = time_in_seconds / 60;
|
||||||
|
time_in_seconds = time_in_seconds % 60;
|
||||||
|
|
||||||
|
StringBuilder builder;
|
||||||
|
|
||||||
|
if (hours > 0)
|
||||||
|
builder.appendff("{:02}:", hours);
|
||||||
|
builder.appendff("{:02}:", minutes);
|
||||||
|
builder.appendff("{:02}", time_in_seconds);
|
||||||
|
|
||||||
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
using AK::human_readable_digital_time;
|
||||||
using AK::human_readable_size;
|
using AK::human_readable_size;
|
||||||
using AK::human_readable_size_long;
|
using AK::human_readable_size_long;
|
||||||
using AK::human_readable_time;
|
using AK::human_readable_time;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue