mirror of
https://github.com/clangen/musikcube.git
synced 2024-12-29 00:17:49 +00:00
Added the ability to format durations with hours.
This commit is contained in:
parent
fe752a0d6f
commit
4a077922ae
@ -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);
|
||||
}
|
||||
|
||||
} } }
|
||||
|
@ -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);
|
||||
|
||||
} } }
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user