6 // ===============================================
7 // Time processing and counting functions/macros
8 // ===============================================
10 #define count_years_decs(time, decs) sprintf(CTX(_("CI_DEC^%s years")), ftos_decimals(time, decs))
11 #define count_years(time) \
13 CTX(_("CI_ZER^%d years")), /* zeroth */ \
14 CTX(_("CI_FIR^%d year")), /* first */ \
15 CTX(_("CI_SEC^%d years")), /* year */ \
16 CTX(_("CI_THI^%d years")), /* third */ \
17 CTX(_("CI_MUL^%d years"))) /* multi */
19 #define count_weeks_decs(time, decs) sprintf(CTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs))
20 #define count_weeks(time) \
22 CTX(_("CI_ZER^%d weeks")), /* zeroth */ \
23 CTX(_("CI_FIR^%d week")), /* first */ \
24 CTX(_("CI_SEC^%d weeks")), /* week */ \
25 CTX(_("CI_THI^%d weeks")), /* third */ \
26 CTX(_("CI_MUL^%d weeks"))) /* multi */
28 #define count_days_decs(time, decs) sprintf(CTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))
29 #define count_days(time) \
31 CTX(_("CI_ZER^%d days")), /* zeroth */ \
32 CTX(_("CI_FIR^%d day")), /* first */ \
33 CTX(_("CI_SEC^%d days")), /* day */ \
34 CTX(_("CI_THI^%d days")), /* third */ \
35 CTX(_("CI_MUL^%d days"))) /* multi */
37 #define count_hours_decs(time, decs) sprintf(CTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs))
38 #define count_hours(time) \
40 CTX(_("CI_ZER^%d hours")), /* zeroth */ \
41 CTX(_("CI_FIR^%d hour")), /* first */ \
42 CTX(_("CI_SEC^%d hours")), /* hour */ \
43 CTX(_("CI_THI^%d hours")), /* third */ \
44 CTX(_("CI_MUL^%d hours"))) /* multi */
47 #define count_minutes_decs(time, decs) sprintf(CTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))
48 #define count_minutes(time) \
50 CTX(_("CI_ZER^%d minutes")), /* zeroth */ \
51 CTX(_("CI_FIR^%d minute")), /* first */ \
52 CTX(_("CI_SEC^%d minutes")), /* minute */ \
53 CTX(_("CI_THI^%d minutes")), /* third */ \
54 CTX(_("CI_MUL^%d minutes"))) /* multi */
56 #define count_seconds_decs(time, decs) sprintf(CTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))
57 #define count_seconds(time) \
59 CTX(_("CI_ZER^%d seconds")), /* zeroth */ \
60 CTX(_("CI_FIR^%d second")), /* first */ \
61 CTX(_("CI_SEC^%d seconds")), /* second */ \
62 CTX(_("CI_THI^%d seconds")), /* third */ \
63 CTX(_("CI_MUL^%d seconds"))) /* multi */
65 string count_ordinal(int interval)
67 // This function is designed primarily for the English language, it's impossible
68 // to accomodate all languages unless we do a specific function for each one...
69 // and since that's not technically feasible/practical, this is all we've got folks.
71 // Basically, it just allows you to represent a number or count in different ways
72 // depending on the number... like, with count_ordinal you can provide integers
73 // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way.
74 if (floor((interval % 100) / 10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
76 // otherwise, check normally for 1st,2nd,3rd insertions
77 switch (interval % 10)
79 case 1: return sprintf(_("%dst"), interval);
80 case 2: return sprintf(_("%dnd"), interval);
81 case 3: return sprintf(_("%drd"), interval);
82 default: return sprintf(_("%dth"), interval);
85 else { return sprintf(_("%dth"), interval); }
90 string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
92 // This function is designed primarily for the English language, it's impossible
93 // to accomodate all languages unless we do a specific function for each one...
94 // and since that's not technically feasible/practical, this is all we've got folks.
96 // Here you can insert specific strings based on the interval number, so you could do
97 // i.e. count_seconds which outputs like this:
102 // etc... minutes, hours, days, etc.
104 switch (floor(interval))
106 case 0: return sprintf(zeroth, interval);
109 if (interval == 1) // EXACTLY value of 1
110 return sprintf(first, interval);
111 else return sprintf(multi, interval);
113 case 2: return sprintf(second, interval);
114 case 3: return sprintf(third, interval);
115 default: return sprintf(multi, interval);
120 string process_time(float outputtype, float seconds)
122 float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0;
123 float tmp_years = 0, tmp_weeks = 0, tmp_days = 0;
125 tmp_seconds = floor(seconds);
129 tmp_minutes = floor(tmp_seconds / 60);
133 tmp_seconds -= (tmp_minutes * 60);
134 tmp_hours = floor(tmp_minutes / 60);
138 tmp_minutes -= (tmp_hours * 60);
139 tmp_days = floor(tmp_hours / 24);
143 tmp_hours -= (tmp_days * 24);
144 tmp_weeks = floor(tmp_days / 7);
148 tmp_days -= (tmp_weeks * 7);
149 tmp_years = floor(tmp_weeks / 52);
158 case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds);
163 output = count_seconds(tmp_seconds);
169 count_minutes(tmp_minutes),
170 ((output != "") ? sprintf(", %s", output) : ""));
177 count_hours(tmp_hours),
178 ((output != "") ? sprintf(", %s", output) : ""));
185 count_days(tmp_days),
186 ((output != "") ? sprintf(", %s", output) : ""));
193 count_weeks(tmp_weeks),
194 ((output != "") ? sprintf(", %s", output) : ""));
201 count_years(tmp_years),
202 ((output != "") ? sprintf(", %s", output) : ""));
211 output = count_hours(tmp_hours);
213 if (tmp_weeks) tmp_days += (tmp_weeks * 7);
214 if (tmp_years) tmp_days += (tmp_years * 365);
219 count_days(tmp_days),
220 ((output != "") ? sprintf(", %s", output) : ""));