5 // ===============================================
6 // Time processing and counting functions/macros
7 // ===============================================
9 #define count_years_decs(time, decs) sprintf(CTX(_("CI_DEC^%s years")), ftos_decimals(time, decs))
10 #define count_years(time) \
12 CTX(_("CI_ZER^%d years")), /* zeroth */ \
13 CTX(_("CI_FIR^%d year")), /* first */ \
14 CTX(_("CI_SEC^%d years")), /* year */ \
15 CTX(_("CI_THI^%d years")), /* third */ \
16 CTX(_("CI_MUL^%d years"))) /* multi */
18 #define count_weeks_decs(time, decs) sprintf(CTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs))
19 #define count_weeks(time) \
21 CTX(_("CI_ZER^%d weeks")), /* zeroth */ \
22 CTX(_("CI_FIR^%d week")), /* first */ \
23 CTX(_("CI_SEC^%d weeks")), /* week */ \
24 CTX(_("CI_THI^%d weeks")), /* third */ \
25 CTX(_("CI_MUL^%d weeks"))) /* multi */
27 #define count_days_decs(time, decs) sprintf(CTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))
28 #define count_days(time) \
30 CTX(_("CI_ZER^%d days")), /* zeroth */ \
31 CTX(_("CI_FIR^%d day")), /* first */ \
32 CTX(_("CI_SEC^%d days")), /* day */ \
33 CTX(_("CI_THI^%d days")), /* third */ \
34 CTX(_("CI_MUL^%d days"))) /* multi */
36 #define count_hours_decs(time, decs) sprintf(CTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs))
37 #define count_hours(time) \
39 CTX(_("CI_ZER^%d hours")), /* zeroth */ \
40 CTX(_("CI_FIR^%d hour")), /* first */ \
41 CTX(_("CI_SEC^%d hours")), /* hour */ \
42 CTX(_("CI_THI^%d hours")), /* third */ \
43 CTX(_("CI_MUL^%d hours"))) /* multi */
46 #define count_minutes_decs(time, decs) sprintf(CTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))
47 #define count_minutes(time) \
49 CTX(_("CI_ZER^%d minutes")), /* zeroth */ \
50 CTX(_("CI_FIR^%d minute")), /* first */ \
51 CTX(_("CI_SEC^%d minutes")), /* minute */ \
52 CTX(_("CI_THI^%d minutes")), /* third */ \
53 CTX(_("CI_MUL^%d minutes"))) /* multi */
55 #define count_seconds_decs(time, decs) sprintf(CTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))
56 #define count_seconds(time) \
58 CTX(_("CI_ZER^%d seconds")), /* zeroth */ \
59 CTX(_("CI_FIR^%d second")), /* first */ \
60 CTX(_("CI_SEC^%d seconds")), /* second */ \
61 CTX(_("CI_THI^%d seconds")), /* third */ \
62 CTX(_("CI_MUL^%d seconds"))) /* multi */
64 string count_ordinal(int interval)
66 // This function is designed primarily for the English language, it's impossible
67 // to accomodate all languages unless we do a specific function for each one...
68 // and since that's not technically feasible/practical, this is all we've got folks.
70 // Basically, it just allows you to represent a number or count in different ways
71 // depending on the number... like, with count_ordinal you can provide integers
72 // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way.
73 if (floor((interval % 100) / 10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
75 // otherwise, check normally for 1st,2nd,3rd insertions
76 switch (interval % 10)
78 case 1: return sprintf(_("%dst"), interval);
79 case 2: return sprintf(_("%dnd"), interval);
80 case 3: return sprintf(_("%drd"), interval);
81 default: return sprintf(_("%dth"), interval);
84 else { return sprintf(_("%dth"), interval); }
89 string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
91 // This function is designed primarily for the English language, it's impossible
92 // to accomodate all languages unless we do a specific function for each one...
93 // and since that's not technically feasible/practical, this is all we've got folks.
95 // Here you can insert specific strings based on the interval number, so you could do
96 // i.e. count_seconds which outputs like this:
101 // etc... minutes, hours, days, etc.
103 switch (floor(interval))
105 case 0: return sprintf(zeroth, interval);
108 if (interval == 1) // EXACTLY value of 1
109 return sprintf(first, interval);
110 else return sprintf(multi, interval);
112 case 2: return sprintf(second, interval);
113 case 3: return sprintf(third, interval);
114 default: return sprintf(multi, interval);
119 string process_time(float outputtype, float seconds)
121 float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0;
122 float tmp_years = 0, tmp_weeks = 0, tmp_days = 0;
124 tmp_seconds = floor(seconds);
128 tmp_minutes = floor(tmp_seconds / 60);
132 tmp_seconds -= (tmp_minutes * 60);
133 tmp_hours = floor(tmp_minutes / 60);
137 tmp_minutes -= (tmp_hours * 60);
138 tmp_days = floor(tmp_hours / 24);
142 tmp_hours -= (tmp_days * 24);
143 tmp_weeks = floor(tmp_days / 7);
147 tmp_days -= (tmp_weeks * 7);
148 tmp_years = floor(tmp_weeks / 52);
157 case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds);
162 output = count_seconds(tmp_seconds);
168 count_minutes(tmp_minutes),
169 ((output != "") ? sprintf(", %s", output) : ""));
176 count_hours(tmp_hours),
177 ((output != "") ? sprintf(", %s", output) : ""));
184 count_days(tmp_days),
185 ((output != "") ? sprintf(", %s", output) : ""));
192 count_weeks(tmp_weeks),
193 ((output != "") ? sprintf(", %s", output) : ""));
200 count_years(tmp_years),
201 ((output != "") ? sprintf(", %s", output) : ""));
210 output = count_hours(tmp_hours);
212 if (tmp_weeks) tmp_days += (tmp_weeks * 7);
213 if (tmp_years) tmp_days += (tmp_years * 365);
218 count_days(tmp_days),
219 ((output != "") ? sprintf(", %s", output) : ""));