4 // ===============================================
5 // Time processing and counting functions/macros
6 // ===============================================
8 #define count_years_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s years")), ftos_decimals(time, decs))
9 #define count_years(time) count_fill(time, \
10 ZCTX(_("CI_ZER^%d years")), /* zeroth */ \
11 ZCTX(_("CI_FIR^%d year")), /* first */ \
12 ZCTX(_("CI_SEC^%d years")), /* year */ \
13 ZCTX(_("CI_THI^%d years")), /* third */ \
14 ZCTX(_("CI_MUL^%d years"))) /* multi */
16 #define count_weeks_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs))
17 #define count_weeks(time) count_fill(time, \
18 ZCTX(_("CI_ZER^%d weeks")), /* zeroth */ \
19 ZCTX(_("CI_FIR^%d week")), /* first */ \
20 ZCTX(_("CI_SEC^%d weeks")), /* week */ \
21 ZCTX(_("CI_THI^%d weeks")), /* third */ \
22 ZCTX(_("CI_MUL^%d weeks"))) /* multi */
24 #define count_days_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))
25 #define count_days(time) count_fill(time, \
26 ZCTX(_("CI_ZER^%d days")), /* zeroth */ \
27 ZCTX(_("CI_FIR^%d day")), /* first */ \
28 ZCTX(_("CI_SEC^%d days")), /* day */ \
29 ZCTX(_("CI_THI^%d days")), /* third */ \
30 ZCTX(_("CI_MUL^%d days"))) /* multi */
32 #define count_hours_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs))
33 #define count_hours(time) count_fill(time, \
34 ZCTX(_("CI_ZER^%d hours")), /* zeroth */ \
35 ZCTX(_("CI_FIR^%d hour")), /* first */ \
36 ZCTX(_("CI_SEC^%d hours")), /* hour */ \
37 ZCTX(_("CI_THI^%d hours")), /* third */ \
38 ZCTX(_("CI_MUL^%d hours"))) /* multi */
41 #define count_minutes_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))
42 #define count_minutes(time) count_fill(time, \
43 ZCTX(_("CI_ZER^%d minutes")), /* zeroth */ \
44 ZCTX(_("CI_FIR^%d minute")), /* first */ \
45 ZCTX(_("CI_SEC^%d minutes")), /* minute */ \
46 ZCTX(_("CI_THI^%d minutes")), /* third */ \
47 ZCTX(_("CI_MUL^%d minutes"))) /* multi */
49 #define count_seconds_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))
50 #define count_seconds(time) count_fill(time, \
51 ZCTX(_("CI_ZER^%d seconds")), /* zeroth */ \
52 ZCTX(_("CI_FIR^%d second")), /* first */ \
53 ZCTX(_("CI_SEC^%d seconds")), /* second */ \
54 ZCTX(_("CI_THI^%d seconds")), /* third */ \
55 ZCTX(_("CI_MUL^%d seconds"))) /* multi */
57 string count_ordinal(int interval)
59 // This function is designed primarily for the English language, it's impossible
60 // to accomodate all languages unless we do a specific function for each one...
61 // and since that's not technically feasible/practical, this is all we've got folks.
63 // Basically, it just allows you to represent a number or count in different ways
64 // depending on the number... like, with count_ordinal you can provide integers
65 // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way.
66 if(floor((interval % 100)/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
68 // otherwise, check normally for 1st,2nd,3rd insertions
71 case 1: return sprintf(_("%dst"), interval);
72 case 2: return sprintf(_("%dnd"), interval);
73 case 3: return sprintf(_("%drd"), interval);
74 default: return sprintf(_("%dth"), interval);
77 else { return sprintf(_("%dth"), interval); }
82 string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
84 // This function is designed primarily for the English language, it's impossible
85 // to accomodate all languages unless we do a specific function for each one...
86 // and since that's not technically feasible/practical, this is all we've got folks.
88 // Here you can insert specific strings based on the interval number, so you could do
89 // i.e. count_seconds which outputs like this:
94 // etc... minutes, hours, days, etc.
96 switch(floor(interval))
98 case 0: return sprintf(zeroth, interval);
101 if(interval == 1) // EXACTLY value of 1
102 return sprintf(first, interval);
104 return sprintf(multi, interval);
106 case 2: return sprintf(second, interval);
107 case 3: return sprintf(third, interval);
108 default: return sprintf(multi, interval);
113 string process_time(float outputtype, float seconds)
115 float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0;
116 float tmp_years = 0, tmp_weeks = 0, tmp_days = 0;
118 tmp_seconds = floor(seconds);
122 tmp_minutes = floor(tmp_seconds / 60);
126 tmp_seconds -= (tmp_minutes * 60);
127 tmp_hours = floor(tmp_minutes / 60);
131 tmp_minutes -= (tmp_hours * 60);
132 tmp_days = floor(tmp_hours / 24);
136 tmp_hours -= (tmp_days * 24);
137 tmp_weeks = floor(tmp_days / 7);
141 tmp_days -= (tmp_weeks * 7);
142 tmp_years = floor(tmp_weeks / 52);
151 case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds);
156 output = count_seconds(tmp_seconds);
162 count_minutes(tmp_minutes),
163 ((output != "") ? sprintf(", %s", output) : ""));
170 count_hours(tmp_hours),
171 ((output != "") ? sprintf(", %s", output) : ""));
178 count_days(tmp_days),
179 ((output != "") ? sprintf(", %s", output) : ""));
186 count_weeks(tmp_weeks),
187 ((output != "") ? sprintf(", %s", output) : ""));
194 count_years(tmp_years),
195 ((output != "") ? sprintf(", %s", output) : ""));
204 output = count_hours(tmp_hours);
206 if(tmp_weeks) { tmp_days += (tmp_weeks * 7); }
207 if(tmp_years) { tmp_days += (tmp_years * 365); }
212 count_days(tmp_days),
213 ((output != "") ? sprintf(", %s", output) : ""));