aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-08-29 23:18:40 +0200
committerMax Kellermann <max@duempel.org>2014-08-29 23:18:40 +0200
commit7df8e1eab27c9539acad3f843d8a882ea9b3e71c (patch)
treefa426c2d1bc0db6ab0a3f2445f624914a86c4265 /src
parent3158955198fbdc71319cd3418523d851e6d47106 (diff)
downloadmpd-7df8e1eab27c9539acad3f843d8a882ea9b3e71c.tar.gz
mpd-7df8e1eab27c9539acad3f843d8a882ea9b3e71c.tar.xz
mpd-7df8e1eab27c9539acad3f843d8a882ea9b3e71c.zip
db/Count: use std::chrono::duration for the total time
Use milliseconds precision to reduce rounding errors.
Diffstat (limited to '')
-rw-r--r--src/db/Count.cxx15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/db/Count.cxx b/src/db/Count.cxx
index fecd901e5..b58ac53e9 100644
--- a/src/db/Count.cxx
+++ b/src/db/Count.cxx
@@ -30,10 +30,10 @@
struct SearchStats {
unsigned n_songs;
- unsigned long total_time_s;
+ std::chrono::duration<std::uint64_t, SongTime::period> total_duration;
constexpr SearchStats()
- :n_songs(0), total_time_s(0) {}
+ :n_songs(0), total_duration(0) {}
};
class TagCountMap : public std::map<std::string, SearchStats> {
@@ -42,10 +42,13 @@ class TagCountMap : public std::map<std::string, SearchStats> {
static void
PrintSearchStats(Client &client, const SearchStats &stats)
{
+ unsigned total_duration_s =
+ std::chrono::duration_cast<std::chrono::seconds>(stats.total_duration).count();
+
client_printf(client,
"songs: %u\n"
- "playtime: %lu\n",
- stats.n_songs, stats.total_time_s);
+ "playtime: %u\n",
+ stats.n_songs, total_duration_s);
}
static void
@@ -67,7 +70,7 @@ stats_visitor_song(SearchStats &stats, const LightSong &song)
const auto duration = song.GetDuration();
if (!duration.IsNegative())
- stats.total_time_s += duration.ToS();
+ stats.total_duration += duration;
return true;
}
@@ -83,7 +86,7 @@ CollectGroupCounts(TagCountMap &map, TagType group, const Tag &tag)
SearchStats &s = r.first->second;
++s.n_songs;
if (!tag.duration.IsNegative())
- s.total_time_s += tag.duration.ToS();
+ s.total_duration += tag.duration;
found = true;
}