MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / os_date

Function os_date

extlibs/lua/src/loslib.c:302–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300
301
302static int os_date (lua_State *L) {
303 size_t slen;
304 const char *s = luaL_optlstring(L, 1, "%c", &slen);
305 time_t t = luaL_opt(L, l_checktime, 2, time(NULL));
306 const char *se = s + slen; /* 's' end */
307 struct tm tmr, *stm;
308 if (*s == '!') { /* UTC? */
309 stm = l_gmtime(&t, &tmr);
310 s++; /* skip '!' */
311 }
312 else
313 stm = l_localtime(&t, &tmr);
314 if (stm == NULL) /* invalid date? */
315 return luaL_error(L,
316 "date result cannot be represented in this installation");
317 if (strcmp(s, "*t") == 0) {
318 lua_createtable(L, 0, 9); /* 9 = number of fields */
319 setallfields(L, stm);
320 }
321 else {
322 char cc[4]; /* buffer for individual conversion specifiers */
323 luaL_Buffer b;
324 cc[0] = '%';
325 luaL_buffinit(L, &b);
326 while (s < se) {
327 if (*s != '%') /* not a conversion specifier? */
328 luaL_addchar(&b, *s++);
329 else {
330 size_t reslen;
331 char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT);
332 s++; /* skip '%' */
333 s = checkoption(L, s, se - s, cc + 1); /* copy specifier to 'cc' */
334 reslen = strftime(buff, SIZETIMEFMT, cc, stm);
335 luaL_addsize(&b, reslen);
336 }
337 }
338 luaL_pushresult(&b);
339 }
340 return 1;
341}
342
343
344static int os_time (lua_State *L) {

Callers

nothing calls this directly

Calls 9

luaL_optlstringFunction · 0.85
luaL_errorFunction · 0.85
lua_createtableFunction · 0.85
setallfieldsFunction · 0.85
checkoptionFunction · 0.85
strftimeFunction · 0.85
luaL_buffinitFunction · 0.70
luaL_prepbuffsizeFunction · 0.70
luaL_pushresultFunction · 0.70

Tested by

no test coverage detected