uses integers for time

This commit is contained in:
Roberto Ierusalimschy
2013-05-14 12:57:11 -03:00
parent bef345a4b8
commit 4ad9970649

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: loslib.c,v 1.39 2012/05/23 15:37:09 roberto Exp roberto $ ** $Id: loslib.c,v 1.40 2012/10/19 15:54:02 roberto Exp roberto $
** Standard Operating System library ** Standard Operating System library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -194,7 +194,7 @@ static const char *checkoption (lua_State *L, const char *conv, char *buff) {
static int os_date (lua_State *L) { static int os_date (lua_State *L) {
const char *s = luaL_optstring(L, 1, "%c"); const char *s = luaL_optstring(L, 1, "%c");
time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); time_t t = luaL_opt(L, (time_t)luaL_checkinteger, 2, time(NULL));
struct tm tmr, *stm; struct tm tmr, *stm;
if (*s == '!') { /* UTC? */ if (*s == '!') { /* UTC? */
stm = l_gmtime(&t, &tmr); stm = l_gmtime(&t, &tmr);
@@ -258,14 +258,14 @@ static int os_time (lua_State *L) {
if (t == (time_t)(-1)) if (t == (time_t)(-1))
lua_pushnil(L); lua_pushnil(L);
else else
lua_pushnumber(L, (lua_Number)t); lua_pushinteger(L, t);
return 1; return 1;
} }
static int os_difftime (lua_State *L) { static int os_difftime (lua_State *L) {
lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), lua_pushnumber(L, difftime((time_t)(luaL_checkinteger(L, 1)),
(time_t)(luaL_optnumber(L, 2, 0)))); (time_t)(luaL_optinteger(L, 2, 0))));
return 1; return 1;
} }