MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / os_date

Function os_date

third-party/lua-5.2.4/src/loslib.c:195–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193
194
195static int os_date (lua_State *L) {
196 const char *s = luaL_optstring(L, 1, "%c");
197 time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
198 struct tm tmr, *stm;
199 if (*s == '!') { /* UTC? */
200 stm = l_gmtime(&t, &tmr);
201 s++; /* skip `!' */
202 }
203 else
204 stm = l_localtime(&t, &tmr);
205 if (stm == NULL) /* invalid date? */
206 lua_pushnil(L);
207 else if (strcmp(s, "*t") == 0) {
208 lua_createtable(L, 0, 9); /* 9 = number of fields */
209 setfield(L, "sec", stm->tm_sec);
210 setfield(L, "min", stm->tm_min);
211 setfield(L, "hour", stm->tm_hour);
212 setfield(L, "day", stm->tm_mday);
213 setfield(L, "month", stm->tm_mon+1);
214 setfield(L, "year", stm->tm_year+1900);
215 setfield(L, "wday", stm->tm_wday+1);
216 setfield(L, "yday", stm->tm_yday+1);
217 setboolfield(L, "isdst", stm->tm_isdst);
218 }
219 else {
220 char cc[4];
221 luaL_Buffer b;
222 cc[0] = '%';
223 luaL_buffinit(L, &b);
224 while (*s) {
225 if (*s != '%') /* no conversion specifier? */
226 luaL_addchar(&b, *s++);
227 else {
228 size_t reslen;
229 char buff[200]; /* should be big enough for any conversion result */
230 s = checkoption(L, s + 1, cc);
231 reslen = strftime(buff, sizeof(buff), cc, stm);
232 luaL_addlstring(&b, buff, reslen);
233 }
234 }
235 luaL_pushresult(&b);
236 }
237 return 1;
238}
239
240
241static int os_time (lua_State *L) {

Callers

nothing calls this directly

Calls 8

lua_pushnilFunction · 0.70
lua_createtableFunction · 0.70
setfieldFunction · 0.70
setboolfieldFunction · 0.70
luaL_buffinitFunction · 0.70
checkoptionFunction · 0.70
luaL_addlstringFunction · 0.70
luaL_pushresultFunction · 0.70

Tested by

no test coverage detected