6 // ===============================================
7 // Time processing and counting functions/macros
8 // ===============================================
10 #define count_years_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s years")), ftos_decimals(time, decs))
11 #define count_years(time) count_fill(time, \
12 ZCTX(_("CI_ZER^%d years")), /* zeroth */ \
13 ZCTX(_("CI_FIR^%d year")), /* first */ \
14 ZCTX(_("CI_SEC^%d years")), /* year */ \
15 ZCTX(_("CI_THI^%d years")), /* third */ \
16 ZCTX(_("CI_MUL^%d years"))) /* multi */
18 #define count_weeks_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs))
19 #define count_weeks(time) count_fill(time, \
20 ZCTX(_("CI_ZER^%d weeks")), /* zeroth */ \
21 ZCTX(_("CI_FIR^%d week")), /* first */ \
22 ZCTX(_("CI_SEC^%d weeks")), /* week */ \
23 ZCTX(_("CI_THI^%d weeks")), /* third */ \
24 ZCTX(_("CI_MUL^%d weeks"))) /* multi */
26 #define count_days_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))
27 #define count_days(time) count_fill(time, \
28 ZCTX(_("CI_ZER^%d days")), /* zeroth */ \
29 ZCTX(_("CI_FIR^%d day")), /* first */ \
30 ZCTX(_("CI_SEC^%d days")), /* day */ \
31 ZCTX(_("CI_THI^%d days")), /* third */ \
32 ZCTX(_("CI_MUL^%d days"))) /* multi */
34 #define count_hours_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs))
35 #define count_hours(time) count_fill(time, \
36 ZCTX(_("CI_ZER^%d hours")), /* zeroth */ \
37 ZCTX(_("CI_FIR^%d hour")), /* first */ \
38 ZCTX(_("CI_SEC^%d hours")), /* hour */ \
39 ZCTX(_("CI_THI^%d hours")), /* third */ \
40 ZCTX(_("CI_MUL^%d hours"))) /* multi */
43 #define count_minutes_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))
44 #define count_minutes(time) count_fill(time, \
45 ZCTX(_("CI_ZER^%d minutes")), /* zeroth */ \
46 ZCTX(_("CI_FIR^%d minute")), /* first */ \
47 ZCTX(_("CI_SEC^%d minutes")), /* minute */ \
48 ZCTX(_("CI_THI^%d minutes")), /* third */ \
49 ZCTX(_("CI_MUL^%d minutes"))) /* multi */
51 #define count_seconds_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))
52 #define count_seconds(time) count_fill(time, \
53 ZCTX(_("CI_ZER^%d seconds")), /* zeroth */ \
54 ZCTX(_("CI_FIR^%d second")), /* first */ \
55 ZCTX(_("CI_SEC^%d seconds")), /* second */ \
56 ZCTX(_("CI_THI^%d seconds")), /* third */ \
57 ZCTX(_("CI_MUL^%d seconds"))) /* multi */
59 string count_ordinal(int interval)
61 // This function is designed primarily for the English language, it's impossible
62 // to accomodate all languages unless we do a specific function for each one...
63 // and since that's not technically feasible/practical, this is all we've got folks.
65 // Basically, it just allows you to represent a number or count in different ways
66 // depending on the number... like, with count_ordinal you can provide integers
67 // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way.
68 if(floor((interval % 100)/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
70 // otherwise, check normally for 1st,2nd,3rd insertions
73 case 1: return sprintf(_("%dst"), interval);
74 case 2: return sprintf(_("%dnd"), interval);
75 case 3: return sprintf(_("%drd"), interval);
76 default: return sprintf(_("%dth"), interval);
79 else { return sprintf(_("%dth"), interval); }
84 string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
86 // This function is designed primarily for the English language, it's impossible
87 // to accomodate all languages unless we do a specific function for each one...
88 // and since that's not technically feasible/practical, this is all we've got folks.
90 // Here you can insert specific strings based on the interval number, so you could do
91 // i.e. count_seconds which outputs like this:
96 // etc... minutes, hours, days, etc.
98 switch(floor(interval))
100 case 0: return sprintf(zeroth, interval);
103 if(interval == 1) // EXACTLY value of 1
104 return sprintf(first, interval);
106 return sprintf(multi, interval);
108 case 2: return sprintf(second, interval);
109 case 3: return sprintf(third, interval);
110 default: return sprintf(multi, interval);
115 string process_time(float outputtype, float seconds)
117 float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0;
118 float tmp_years = 0, tmp_weeks = 0, tmp_days = 0;
120 tmp_seconds = floor(seconds);
124 tmp_minutes = floor(tmp_seconds / 60);
128 tmp_seconds -= (tmp_minutes * 60);
129 tmp_hours = floor(tmp_minutes / 60);
133 tmp_minutes -= (tmp_hours * 60);
134 tmp_days = floor(tmp_hours / 24);
138 tmp_hours -= (tmp_days * 24);
139 tmp_weeks = floor(tmp_days / 7);
143 tmp_days -= (tmp_weeks * 7);
144 tmp_years = floor(tmp_weeks / 52);
153 case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds);
158 output = count_seconds(tmp_seconds);
164 count_minutes(tmp_minutes),
165 ((output != "") ? sprintf(", %s", output) : ""));
172 count_hours(tmp_hours),
173 ((output != "") ? sprintf(", %s", output) : ""));
180 count_days(tmp_days),
181 ((output != "") ? sprintf(", %s", output) : ""));
188 count_weeks(tmp_weeks),
189 ((output != "") ? sprintf(", %s", output) : ""));
196 count_years(tmp_years),
197 ((output != "") ? sprintf(", %s", output) : ""));
206 output = count_hours(tmp_hours);
208 if(tmp_weeks) { tmp_days += (tmp_weeks * 7); }
209 if(tmp_years) { tmp_days += (tmp_years * 365); }
214 count_days(tmp_days),
215 ((output != "") ? sprintf(", %s", output) : ""));