MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / os_date

Function os_date

lib/lua/src/loslib.c:304–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected