1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:07:36 +00:00

Userland: Use AK::human_readable_digital_time() instead of custom code

Use this handy AK function instead of reimplementing the formatting code
several times. The one minor difference is that now, hours are only
shown if the duration is at least an hour long, but that seems like an
improvement to me. :^)
This commit is contained in:
Sam Atkins 2023-07-19 11:05:37 +01:00 committed by Tim Flynn
parent 3533d3e452
commit 7d0f70bfa0
5 changed files with 11 additions and 27 deletions

View file

@ -7,6 +7,7 @@
*/
#include "Game.h"
#include <AK/NumberFormat.h>
#include <Games/Spider/SpiderGML.h>
#include <LibConfig/Client.h>
#include <LibCore/System.h>
@ -29,15 +30,6 @@ enum class StatisticDisplay : u8 {
__Count
};
static DeprecatedString format_seconds(uint64_t seconds_elapsed)
{
uint64_t hours = seconds_elapsed / 3600;
uint64_t minutes = (seconds_elapsed / 60) % 60;
uint64_t seconds = seconds_elapsed % 60;
return DeprecatedString::formatted("{:02}:{:02}:{:02}", hours, minutes, seconds);
}
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix proc exec"));
@ -130,7 +122,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
statusbar.set_text(1, String::formatted("High Score: {}", high_score()).release_value_but_fixme_should_propagate_errors());
break;
case StatisticDisplay::BestTime:
statusbar.set_text(1, String::formatted("Best Time: {}", format_seconds(best_time())).release_value_but_fixme_should_propagate_errors());
statusbar.set_text(1, String::formatted("Best Time: {}", human_readable_digital_time(best_time())).release_value_but_fixme_should_propagate_errors());
break;
default:
VERIFY_NOT_REACHED();
@ -158,7 +150,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto timer = TRY(Core::Timer::create_repeating(1000, [&]() {
++seconds_elapsed;
statusbar.set_text(2, String::formatted("Time: {}", format_seconds(seconds_elapsed)).release_value_but_fixme_should_propagate_errors());
statusbar.set_text(2, String::formatted("Time: {}", human_readable_digital_time(seconds_elapsed)).release_value_but_fixme_should_propagate_errors());
}));
game.on_game_start = [&]() {