X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fcounting.qh;h=303ee6988383d6f9cdfc9a23a561e9e44e0f1fe3;hb=c624e64397b1ac7cbe3b2128a732d2f762443db3;hp=b38ba9d05a9313f670f8fa8bdeede09c565ebf2c;hpb=b945d959784e5b249c66aea4f3326d8ae048f1cd;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/counting.qh b/qcsrc/lib/counting.qh index b38ba9d05..303ee6988 100644 --- a/qcsrc/lib/counting.qh +++ b/qcsrc/lib/counting.qh @@ -61,6 +61,7 @@ _("CI_THI^%d seconds"), /* third */ \ _("CI_MUL^%d seconds")) /* multi */ +// returns 1st, 2nd, 3rd, nth ordinal number from a cardinal number (integer) ERASEABLE string count_ordinal(int interval) { @@ -68,23 +69,20 @@ string count_ordinal(int interval) // to accomodate all languages unless we do a specific function for each one... // and since that's not technically feasible/practical, this is all we've got folks. - // Basically, it just allows you to represent a number or count in different ways - // depending on the number... like, with count_ordinal you can provide integers - // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way. - if (floor((interval % 100) / 10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block + int last2digits = interval % 100; + + // numbers ending with 11, 12 and 13 don't follow the standard pattern + if (last2digits < 4 || last2digits > 20) { - // otherwise, check normally for 1st,2nd,3rd insertions - switch (interval % 10) + switch (last2digits % 10) { case 1: return sprintf(_("%dst"), interval); case 2: return sprintf(_("%dnd"), interval); case 3: return sprintf(_("%drd"), interval); - default: return sprintf(_("%dth"), interval); } } - else { return sprintf(_("%dth"), interval); } - return ""; + return sprintf(_("%dth"), interval); } ERASEABLE @@ -119,10 +117,10 @@ string count_fill(float interval, string zeroth, string first, string second, st } ERASEABLE -string process_time(float outputtype, float seconds) +string process_time(float outputtype, int seconds) { - float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0; - float tmp_years = 0, tmp_weeks = 0, tmp_days = 0; + int tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0; + int tmp_years = 0, tmp_weeks = 0, tmp_days = 0; tmp_seconds = floor(seconds); @@ -161,44 +159,17 @@ string process_time(float outputtype, float seconds) case 2: { string output = ""; - - output = count_seconds(tmp_seconds); - - if (tmp_minutes) - { - output = strcat( - count_minutes(tmp_minutes), - ((output != "") ? strcat(", ", output) : "")); - } - - if (tmp_hours) - { - output = strcat( - count_hours(tmp_hours), - ((output != "") ? strcat(", ", output) : "")); - } - - if (tmp_days) - { - output = strcat( - count_days(tmp_days), - ((output != "") ? strcat(", ", output) : "")); - } - - if (tmp_weeks) - { - output = strcat( - count_weeks(tmp_weeks), - ((output != "") ? strcat(", ", output) : "")); - } - - if (tmp_years) - { - output = strcat( - count_years(tmp_years), - ((output != "") ? strcat(", ", output) : "")); - } - + #define APPEND_TIME(unit) \ + if (tmp_##unit) output = strcat(output, ((output != "") ? ", " : ""), count_##unit(tmp_##unit)) + APPEND_TIME(years); + APPEND_TIME(weeks); + APPEND_TIME(days); + APPEND_TIME(hours); + APPEND_TIME(minutes); + APPEND_TIME(seconds); + #undef APPEND_TIME + if (output == "") + return count_seconds(0); return output; } case 3: