Mercurial > minori
diff src/gui/pages/statistics.cc @ 189:649786bae914
*: etc. code cleanup
I've removed most macros and stuff
dep/animia: [UNTESTED] use raw C++ instead of Objective-C++
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 19:42:33 -0500 |
parents | 9613d72b097e |
children | 4d461ef7d424 |
line wrap: on
line diff
--- a/src/gui/pages/statistics.cc Wed Dec 06 13:44:36 2023 -0500 +++ b/src/gui/pages/statistics.cc Wed Dec 06 19:42:33 2023 -0500 @@ -75,9 +75,11 @@ } /* me abusing macros :) */ -#define ADD_TIME_SEGMENT(r, x, s, p) \ - if (x > 0) \ - r << x << ((x == 1) ? s : p) +static void add_time_segment(std::ostringstream& str, int x, const std::string_view& s, const std::string_view& p) { + if (x > 0) + str << x << ((x == 1) ? s : p); +} + std::string StatisticsPage::MinutesToDateString(const int minutes) { /* ew */ int years = (minutes * (1 / 525949.2F)); @@ -86,10 +88,10 @@ int hours = (minutes * (1 / 60.0F)) - (years * 8765.82F) - (months * 730.485F) - (days * 24); int rest_minutes = (minutes) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440) - (hours * 60); std::ostringstream return_stream; - ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); - ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); - ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); - ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); + add_time_segment(return_stream, years, " year ", " years "); + add_time_segment(return_stream, months, " month ", " months "); + add_time_segment(return_stream, days, " day ", " days "); + add_time_segment(return_stream, hours, " hour ", " hours "); if (rest_minutes > 0 || return_stream.str().size() == 0) return_stream << rest_minutes << ((rest_minutes == 1) ? " minute" : " minutes"); return return_stream.str(); @@ -105,16 +107,15 @@ int seconds = sec - (years * 31556952.0F) - (months * 2629746.0F) - (days * 86400.0F) - (hours * 3600.0F) - (minutes * 60.0F); std::ostringstream return_stream; - ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); - ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); - ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); - ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); - ADD_TIME_SEGMENT(return_stream, minutes, " minute ", " minutes "); + add_time_segment(return_stream, years, " year ", " years "); + add_time_segment(return_stream, months, " month ", " months "); + add_time_segment(return_stream, days, " day ", " days "); + add_time_segment(return_stream, hours, " hour ", " hours "); + add_time_segment(return_stream, minutes, " minute ", " minutes "); if (seconds > 0 || return_stream.str().size() == 0) return_stream << seconds << ((seconds == 1) ? " second" : " seconds"); return return_stream.str(); } -#undef ADD_TIME_SEGMENT inline int GetTotalWithScore(const int score) { int count = 0;