lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

In Lua5.0.2, it's not possible to set negative tm_isdst value
by os.time(). So user must specify correct isdst value to get
proper result.

For example,
$ uname -a
Darwin saga 7.3.0 Darwin Kernel Version 7.3.0: Fri Mar 5 14:22:55 PST 2004; root:xnu/xnu-517.3.15.obj~4/RELEASE_PPC Power Macintosh powerpc
$ TZ=EST5EDT,M4.1.0,M10.5.0 lua
Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> = os.date("%Y-%m-%d %H:%M:%S %Z", os.time({year=2004,month=7,day=1,hour=9})) 2004-07-01 10:00:00 EDT (this result may depends on the operating system) > = os.date("%Y-%m-%d %H:%M:%S %Z", os.time({year=2004,month=7,day=1,hour=9,isdst=true}))
2004-07-01 09:00:00 EDT
>

But getting isdst value is difficult or impossible for some cases.
This patch allows missing isdst to let os.time guess the correct
isdst value.

--- lua-5.0.2/src/lib/liolib.c.orig 2004-05-10 21:15:48.000000000 +0900
+++ lua-5.0.2/src/lib/liolib.c  2004-05-10 21:16:37.000000000 +0900
@@ -605,7 +605,10 @@
   int res;
   lua_pushstring(L, key);
   lua_gettable(L, -2);
-  res = lua_toboolean(L, -1);
+  if (lua_isnil(L, -1))
+    res = -1;
+  else
+    res = lua_toboolean(L, -1);
   lua_pop(L, 1);
   return res;
 }

--
asakawa