MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / os_time

Function os_time

deps/lua/src/loslib.c:170–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168
169
170static int os_time (lua_State *L) {
171 time_t t;
172 if (lua_isnoneornil(L, 1)) /* called without args? */
173 t = time(NULL); /* get current time */
174 else {
175 struct tm ts;
176 luaL_checktype(L, 1, LUA_TTABLE);
177 lua_settop(L, 1); /* make sure table is at the top */
178 ts.tm_sec = getfield(L, "sec", 0);
179 ts.tm_min = getfield(L, "min", 0);
180 ts.tm_hour = getfield(L, "hour", 12);
181 ts.tm_mday = getfield(L, "day", -1);
182 ts.tm_mon = getfield(L, "month", -1) - 1;
183 ts.tm_year = getfield(L, "year", -1) - 1900;
184 ts.tm_isdst = getboolfield(L, "isdst");
185 t = mktime(&ts);
186 }
187 if (t == (time_t)(-1))
188 lua_pushnil(L);
189 else
190 lua_pushnumber(L, (lua_Number)t);
191 return 1;
192}
193
194
195static int os_difftime (lua_State *L) {

Callers

nothing calls this directly

Calls 6

luaL_checktypeFunction · 0.85
lua_settopFunction · 0.85
getfieldFunction · 0.85
getboolfieldFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushnumberFunction · 0.85

Tested by

no test coverage detected