From 7d0d8a1bf0ffbaf073303efc7d7bfc58177277a6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 28 Apr 2021 17:41:58 +0200 Subject: Calculate subscription uploaded time difference correctly when taking timezone into consideration --- src/QuickMedia.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 456bdc6..54308a4 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1019,7 +1019,9 @@ namespace QuickMedia { }; // Returns relative time as a string (approximation) - static std::string timestamp_to_relative_time_str(time_t seconds) { + static std::string seconds_to_relative_time_str(time_t seconds) { + seconds = std::max(0L, seconds); + time_t minutes = seconds / 60; time_t hours = minutes / 60; time_t days = hours / 24; @@ -1068,7 +1070,7 @@ namespace QuickMedia { auto body_item = BodyItem::create(std::move(title_str)); body_item->url = "https://www.youtube.com/watch?v=" + video_id_str; body_item->thumbnail_url = "https://img.youtube.com/vi/" + video_id_str + "/hqdefault.jpg"; - body_item->set_description("Watched " + timestamp_to_relative_time_str(std::max(0l, time_now - timestamp.asInt64()))); + body_item->set_description("Watched " + seconds_to_relative_time_str(time_now - timestamp.asInt64())); body_item->thumbnail_size = sf::Vector2i(175, 131); body_items.push_back(std::move(body_item)); } -- cgit v1.2.3