MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / timeToString

Function timeToString

src/server/gui/core/utils/TimeUtil.cpp:217–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215//////////////////////////////////////////////////////////////////////////
216
217 std::string timeToString(const time_t& _time, const std::string& _format)
218 {
219 const char* f = _format.c_str();
220 const tm timeStruct = *localtime(&_time);
221 char buf[256] = { '\0' };
222 char* s = buf;
223
224 while(*f)
225 {
226 if(*f == '%')
227 {
228 ++f;
229
230 switch(*f++)
231 {
232 case 'Y': // The year, including the century (1900)
233 {
234 const int year = timeStruct.tm_year + 1900;
235 *s++ = (char)((year - (year % 1000)) / 1000) + '0';
236 *s++ = (char)(((year % 1000) - (year % 100)) / 100) + '0';
237 *s++ = (char)(((year % 100) - (year % 10)) / 10) + '0';
238 *s++ = (char)(year % 10) + '0';
239 }
240 break;
241
242 case 'm': // The month number [00,11]
243 {
244 const int mon = timeStruct.tm_mon + 1;
245 *s++ = (char)(mon / 10) + '0';
246 *s++ = (char)(mon % 10) + '0';
247 }
248 break;
249
250 case 'd': // The day of the month [01,31]
251 {
252 *s++ = (char)(timeStruct.tm_mday / 10) + '0';
253 *s++ = (char)(timeStruct.tm_mday % 10) + '0';
254 }
255 break;
256
257 case 'H': // The hour (24-hour clock) [00,23]
258 {
259 *s++ = (char)(timeStruct.tm_hour / 10) + '0';
260 *s++ = (char)(timeStruct.tm_hour % 10) + '0';
261 }
262 break;
263
264 case 'M': // The minute [00,59]
265 {
266 *s++ = (char)(timeStruct.tm_min / 10) + '0';
267 *s++ = (char)(timeStruct.tm_min % 10) + '0';
268 }
269 break;
270
271 case 'S': // The second [00,59]
272 {
273 *s++ = (char)(timeStruct.tm_sec / 10) + '0';
274 *s++ = (char)(timeStruct.tm_sec % 10) + '0';

Callers 3

getDisplayStringMethod · 0.85
getDisplayStringMethod · 0.85
setTimeMethod · 0.85

Calls 1

c_strMethod · 0.80

Tested by

no test coverage detected