mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Added human_readable_time() method for "unsaved changes" dialogs
This commit is contained in:
parent
9ae2285675
commit
0012c03eb5
Notes:
sideshowbarker
2024-07-17 21:16:37 +09:00
Author: https://github.com/Sauler Commit: https://github.com/SerenityOS/serenity/commit/0012c03eb5b Pull-request: https://github.com/SerenityOS/serenity/pull/11627 Reviewed-by: https://github.com/trflynn89
1 changed files with 22 additions and 0 deletions
|
@ -42,7 +42,29 @@ static inline String human_readable_size_long(u64 size)
|
|||
return String::formatted("{} ({} bytes)", human_readable_size(size), size);
|
||||
}
|
||||
|
||||
static inline String human_readable_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("{} hour{} ", hours, hours == 1 ? "" : "s");
|
||||
|
||||
if (minutes > 0)
|
||||
builder.appendff("{} minute{} ", minutes, minutes == 1 ? "" : "s");
|
||||
|
||||
builder.appendff("{} second{}", time_in_seconds, time_in_seconds == 1 ? "" : "s");
|
||||
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::human_readable_size;
|
||||
using AK::human_readable_size_long;
|
||||
using AK::human_readable_time;
|
||||
|
|
Loading…
Reference in a new issue