summaryrefslogtreecommitdiff
path: root/AK/NumberFormat.h
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-08-04 09:36:18 -0400
committerAndreas Kling <kling@serenityos.org>2022-08-05 13:55:13 +0200
commit75b6097c557a60c1139abb0cb84c00a98fc9da75 (patch)
treef05b75e0207303da05d0db30f5c21ac7dd9ada0c /AK/NumberFormat.h
parenta808cfa75cb4db406a2ee84659eff7b4938e3835 (diff)
downloadserenity-75b6097c557a60c1139abb0cb84c00a98fc9da75.zip
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.
Diffstat (limited to 'AK/NumberFormat.h')
-rw-r--r--AK/NumberFormat.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/AK/NumberFormat.h b/AK/NumberFormat.h
index ce778eccc7..610ad686f4 100644
--- a/AK/NumberFormat.h
+++ b/AK/NumberFormat.h
@@ -63,8 +63,27 @@ static inline String human_readable_time(i64 time_in_seconds)
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_long;
using AK::human_readable_time;