mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK+Userland: Return String from human_readable_[digital_]time()
This commit is contained in:
parent
b12541b286
commit
7e8cfb60eb
Notes:
sideshowbarker
2024-07-17 09:41:18 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/7e8cfb60eb Pull-request: https://github.com/SerenityOS/serenity/pull/22917 Reviewed-by: https://github.com/tcl3 ✅
4 changed files with 9 additions and 11 deletions
|
@ -5,10 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/ByteString.h>
|
|
||||||
#include <AK/NumberFormat.h>
|
#include <AK/NumberFormat.h>
|
||||||
#include <AK/NumericLimits.h>
|
#include <AK/NumericLimits.h>
|
||||||
#include <AK/StringView.h>
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -75,7 +73,7 @@ ByteString human_readable_size_long(u64 size, UseThousandsSeparator use_thousand
|
||||||
return ByteString::formatted("{} ({} bytes)", human_readable_size_string, size);
|
return ByteString::formatted("{} ({} bytes)", human_readable_size_string, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteString human_readable_time(i64 time_in_seconds)
|
String human_readable_time(i64 time_in_seconds)
|
||||||
{
|
{
|
||||||
auto days = time_in_seconds / 86400;
|
auto days = time_in_seconds / 86400;
|
||||||
time_in_seconds = time_in_seconds % 86400;
|
time_in_seconds = time_in_seconds % 86400;
|
||||||
|
@ -99,10 +97,10 @@ ByteString human_readable_time(i64 time_in_seconds)
|
||||||
|
|
||||||
builder.appendff("{} second{}", time_in_seconds, time_in_seconds == 1 ? "" : "s");
|
builder.appendff("{} second{}", time_in_seconds, time_in_seconds == 1 ? "" : "s");
|
||||||
|
|
||||||
return builder.to_byte_string();
|
return MUST(builder.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteString human_readable_digital_time(i64 time_in_seconds)
|
String human_readable_digital_time(i64 time_in_seconds)
|
||||||
{
|
{
|
||||||
auto hours = time_in_seconds / 3600;
|
auto hours = time_in_seconds / 3600;
|
||||||
time_in_seconds = time_in_seconds % 3600;
|
time_in_seconds = time_in_seconds % 3600;
|
||||||
|
@ -117,7 +115,7 @@ ByteString human_readable_digital_time(i64 time_in_seconds)
|
||||||
builder.appendff("{:02}:", minutes);
|
builder.appendff("{:02}:", minutes);
|
||||||
builder.appendff("{:02}", time_in_seconds);
|
builder.appendff("{:02}", time_in_seconds);
|
||||||
|
|
||||||
return builder.to_byte_string();
|
return MUST(builder.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/ByteString.h>
|
#include <AK/String.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ ByteString human_readable_size(u64 size, HumanReadableBasedOn based_on = HumanRe
|
||||||
ByteString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, StringView unit = "B"sv, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
ByteString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, StringView unit = "B"sv, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
||||||
|
|
||||||
ByteString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
ByteString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
||||||
ByteString human_readable_time(i64 time_in_seconds);
|
String human_readable_time(i64 time_in_seconds);
|
||||||
ByteString human_readable_digital_time(i64 time_in_seconds);
|
String human_readable_digital_time(i64 time_in_seconds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ ErrorOr<void> PropertiesWindow::create_audio_tab(GUI::TabWidget& tab_widget, Non
|
||||||
|
|
||||||
tab.find_descendant_of_type_named<GUI::Label>("audio_type")->set_text(TRY(String::from_byte_string(loader->format_name())));
|
tab.find_descendant_of_type_named<GUI::Label>("audio_type")->set_text(TRY(String::from_byte_string(loader->format_name())));
|
||||||
auto duration_seconds = loader->total_samples() / loader->sample_rate();
|
auto duration_seconds = loader->total_samples() / loader->sample_rate();
|
||||||
tab.find_descendant_of_type_named<GUI::Label>("audio_duration")->set_text(TRY(String::from_byte_string(human_readable_digital_time(duration_seconds))));
|
tab.find_descendant_of_type_named<GUI::Label>("audio_duration")->set_text(human_readable_digital_time(duration_seconds));
|
||||||
tab.find_descendant_of_type_named<GUI::Label>("audio_sample_rate")->set_text(TRY(String::formatted("{} Hz", loader->sample_rate())));
|
tab.find_descendant_of_type_named<GUI::Label>("audio_sample_rate")->set_text(TRY(String::formatted("{} Hz", loader->sample_rate())));
|
||||||
tab.find_descendant_of_type_named<GUI::Label>("audio_format")->set_text(TRY(String::formatted("{}-bit", loader->bits_per_sample())));
|
tab.find_descendant_of_type_named<GUI::Label>("audio_format")->set_text(TRY(String::formatted("{}-bit", loader->bits_per_sample())));
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ void Field::initialize()
|
||||||
m_timer = Core::Timer::create_repeating(
|
m_timer = Core::Timer::create_repeating(
|
||||||
1000, [this] {
|
1000, [this] {
|
||||||
++m_time_elapsed;
|
++m_time_elapsed;
|
||||||
m_time_label.set_text(String::from_byte_string(human_readable_digital_time(m_time_elapsed)).release_value_but_fixme_should_propagate_errors());
|
m_time_label.set_text(human_readable_digital_time(m_time_elapsed));
|
||||||
},
|
},
|
||||||
this)
|
this)
|
||||||
.release_value_but_fixme_should_propagate_errors();
|
.release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
Loading…
Reference in a new issue