1 // ===============================================
2 // Time processing and counting functions/macros
3 // ===============================================
5 #define count_years_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s years")), ftos_decimals(time, decs))
6 #define count_years(time) count_fill(time, \
7 ZCTX(_("CI_ZER^%d years")), /* zeroth */ \
8 ZCTX(_("CI_FIR^%d year")), /* first */ \
9 ZCTX(_("CI_SEC^%d years")), /* year */ \
10 ZCTX(_("CI_THI^%d years")), /* third */ \
11 ZCTX(_("CI_MUL^%d years"))) /* multi */
13 #define count_weeks_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs))
14 #define count_weeks(time) count_fill(time, \
15 ZCTX(_("CI_ZER^%d weeks")), /* zeroth */ \
16 ZCTX(_("CI_FIR^%d week")), /* first */ \
17 ZCTX(_("CI_SEC^%d weeks")), /* week */ \
18 ZCTX(_("CI_THI^%d weeks")), /* third */ \
19 ZCTX(_("CI_MUL^%d weeks"))) /* multi */
21 #define count_days_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))
22 #define count_days(time) count_fill(time, \
23 ZCTX(_("CI_ZER^%d days")), /* zeroth */ \
24 ZCTX(_("CI_FIR^%d day")), /* first */ \
25 ZCTX(_("CI_SEC^%d days")), /* day */ \
26 ZCTX(_("CI_THI^%d days")), /* third */ \
27 ZCTX(_("CI_MUL^%d days"))) /* multi */
29 #define count_hours_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs))
30 #define count_hours(time) count_fill(time, \
31 ZCTX(_("CI_ZER^%d hours")), /* zeroth */ \
32 ZCTX(_("CI_FIR^%d hour")), /* first */ \
33 ZCTX(_("CI_SEC^%d hours")), /* hour */ \
34 ZCTX(_("CI_THI^%d hours")), /* third */ \
35 ZCTX(_("CI_MUL^%d hours"))) /* multi */
38 #define count_minutes_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))
39 #define count_minutes(time) count_fill(time, \
40 ZCTX(_("CI_ZER^%d minutes")), /* zeroth */ \
41 ZCTX(_("CI_FIR^%d minute")), /* first */ \
42 ZCTX(_("CI_SEC^%d minutes")), /* minute */ \
43 ZCTX(_("CI_THI^%d minutes")), /* third */ \
44 ZCTX(_("CI_MUL^%d minutes"))) /* multi */
46 #define count_seconds_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))
47 #define count_seconds(time) count_fill(time, \
48 ZCTX(_("CI_ZER^%d seconds")), /* zeroth */ \
49 ZCTX(_("CI_FIR^%d second")), /* first */ \
50 ZCTX(_("CI_SEC^%d seconds")), /* second */ \
51 ZCTX(_("CI_THI^%d seconds")), /* third */ \
52 ZCTX(_("CI_MUL^%d seconds"))) /* multi */
54 string count_ordinal(float interval)
56 // This function is designed primarily for the English language, it's impossible
57 // to accomodate all languages unless we do a specific function for each one...
58 // and since that's not technically feasible/practical, this is all we've got folks.
60 // Basically, it just allows you to represent a number or count in different ways
61 // depending on the number... like, with count_ordinal you can provide integers
62 // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way.
63 if(floor((mod(interval, 100))/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
65 // otherwise, check normally for 1st,2nd,3rd insertions
66 switch(mod(interval, 10))
68 case 1: return sprintf(_("%dst"), interval);
69 case 2: return sprintf(_("%dnd"), interval);
70 case 3: return sprintf(_("%drd"), interval);
71 default: return sprintf(_("%dth"), interval);
74 else { return sprintf(_("%dth"), interval); }
79 string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
81 // This function is designed primarily for the English language, it's impossible
82 // to accomodate all languages unless we do a specific function for each one...
83 // and since that's not technically feasible/practical, this is all we've got folks.
85 // Here you can insert specific strings based on the interval number, so you could do
86 // i.e. count_seconds which outputs like this:
91 // etc... minutes, hours, days, etc.
93 switch(floor(interval))
95 case 0: return sprintf(zeroth, interval);
98 if(interval == 1) // EXACTLY value of 1
99 return sprintf(first, interval);
101 return sprintf(multi, interval);
103 case 2: return sprintf(second, interval);
104 case 3: return sprintf(third, interval);
105 default: return sprintf(multi, interval);
110 string process_time(float outputtype, float seconds)
112 float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0;
113 float tmp_years = 0, tmp_weeks = 0, tmp_days = 0;
115 tmp_seconds = floor(seconds);
119 tmp_minutes = floor(tmp_seconds / 60);
123 tmp_seconds -= (tmp_minutes * 60);
124 tmp_hours = floor(tmp_minutes / 60);
128 tmp_minutes -= (tmp_hours * 60);
129 tmp_days = floor(tmp_hours / 24);
133 tmp_hours -= (tmp_days * 24);
134 tmp_weeks = floor(tmp_days / 7);
138 tmp_days -= (tmp_weeks * 7);
139 tmp_years = floor(tmp_weeks / 52);
148 case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds);
153 output = count_seconds(tmp_seconds);
159 count_minutes(tmp_minutes),
160 ((output != "") ? sprintf(", %s", output) : ""));
167 count_hours(tmp_hours),
168 ((output != "") ? sprintf(", %s", output) : ""));
175 count_days(tmp_days),
176 ((output != "") ? sprintf(", %s", output) : ""));
183 count_weeks(tmp_weeks),
184 ((output != "") ? sprintf(", %s", output) : ""));
191 count_years(tmp_years),
192 ((output != "") ? sprintf(", %s", output) : ""));