MCPcopy Create free account
hub / github.com/ddnet/ddnet / str_time

Function str_time

src/base/time.cpp:199–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197#endif
198
199int str_time(int64_t centisecs, int format, char *buffer, int buffer_size)
200{
201 const int sec = 100;
202 const int min = 60 * sec;
203 const int hour = 60 * min;
204 const int day = 24 * hour;
205
206 if(buffer_size <= 0)
207 return -1;
208
209 if(centisecs < 0)
210 centisecs = 0;
211
212 buffer[0] = 0;
213
214 switch(format)
215 {
216 case TIME_DAYS:
217 if(centisecs >= day)
218 return str_format(buffer, buffer_size, "%" PRId64 "d %02" PRId64 ":%02" PRId64 ":%02" PRId64, centisecs / day,
219 (centisecs % day) / hour, (centisecs % hour) / min, (centisecs % min) / sec);
220 [[fallthrough]];
221 case TIME_HOURS:
222 if(centisecs >= hour)
223 return str_format(buffer, buffer_size, "%02" PRId64 ":%02" PRId64 ":%02" PRId64, centisecs / hour,
224 (centisecs % hour) / min, (centisecs % min) / sec);
225 [[fallthrough]];
226 case TIME_MINS:
227 return str_format(buffer, buffer_size, "%02" PRId64 ":%02" PRId64, centisecs / min,
228 (centisecs % min) / sec);
229 case TIME_HOURS_CENTISECS:
230 if(centisecs >= hour)
231 return str_format(buffer, buffer_size, "%02" PRId64 ":%02" PRId64 ":%02" PRId64 ".%02" PRId64, centisecs / hour,
232 (centisecs % hour) / min, (centisecs % min) / sec, centisecs % sec);
233 [[fallthrough]];
234 case TIME_MINS_CENTISECS:
235 if(centisecs >= min)
236 return str_format(buffer, buffer_size, "%02" PRId64 ":%02" PRId64 ".%02" PRId64, centisecs / min,
237 (centisecs % min) / sec, centisecs % sec);
238 [[fallthrough]];
239 case TIME_SECS_CENTISECS:
240 return str_format(buffer, buffer_size, "%02" PRId64 ".%02" PRId64, (centisecs % min) / sec, centisecs % sec);
241 }
242
243 return -1;
244}
245
246int str_time_float(float secs, int format, char *buffer, int buffer_size)
247{

Callers 15

RenderTimeMethod · 0.85
RenderGameTimerMethod · 0.85
RenderScoreHudMethod · 0.85
RenderDDRaceEffectsMethod · 0.85
RenderRecordMethod · 0.85
RenderDemoPlayerMethod · 0.85
RenderDemoBrowserListMethod · 0.85
RenderGhostMethod · 0.85

Calls 1

str_formatFunction · 0.85

Tested by 1

TESTFunction · 0.68