Added the ability to format durations with hours.

This commit is contained in:
casey langen 2021-01-26 15:25:38 -08:00
parent fe752a0d6f
commit 4a077922ae
3 changed files with 32 additions and 2 deletions

View File

@ -42,7 +42,29 @@ static std::string formatDuration(N seconds) {
N mins = (seconds / 60);
N secs = seconds - (mins * 60);
char buffer[128];
snprintf(buffer, sizeof(buffer), "%d:%02d", narrow_cast<int>(mins), narrow_cast<int>(secs));
snprintf(
buffer,
sizeof(buffer),
"%d:%02d",
narrow_cast<int>(mins),
narrow_cast<int>(secs));
return std::string(buffer);
}
template <typename N>
static std::string formatDurationWithHours(N seconds) {
N hours = (seconds / 3600);
seconds -= hours * 3600;
N mins = (seconds / 60);
N secs = seconds - (mins * 60);
char buffer[128];
snprintf(
buffer,
sizeof(buffer),
"%d:%02d:%02d",
narrow_cast<int>(hours),
narrow_cast<int>(mins),
narrow_cast<int>(secs));
return std::string(buffer);
}
@ -69,4 +91,11 @@ namespace musik { namespace core { namespace duration {
return "0:00";
}
std::string DurationWithHours(size_t seconds) {
if (seconds < 3600) {
return formatDuration(seconds);
}
return formatDurationWithHours(seconds);
}
} } }

View File

@ -42,5 +42,6 @@ namespace musik { namespace core { namespace duration {
std::string Duration(int seconds);
std::string Duration(size_t seconds);
std::string Duration(double seconds);
std::string DurationWithHours(size_t seconds);
} } }

View File

@ -503,7 +503,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(cursespp::ScrollableWi
auto duration = this->parent.headers.DurationFromAdapterIndex(rawIndex);
if (duration > 0) {
album += " - " + core::duration::Duration(duration);
album += " - " + core::duration::DurationWithHours(duration);
}
album = text::Ellipsize(album, this->GetWidth());