mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
AK: Added human_readable_time() method for "unsaved changes" dialogs
This commit is contained in:
parent
9ae2285675
commit
0012c03eb5
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);
|
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;
|
||||||
using AK::human_readable_size_long;
|
using AK::human_readable_size_long;
|
||||||
|
using AK::human_readable_time;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue