• Subject: DST PROBLEM in os.time
• Date: Sun, 11 Sep 2005 21:48:58 -0700 (PDT)

```The os.time(tmtable) function convert tmtable
expressed as
local time into a numeric time since the
Epoch, or nil if  tmtable cannot be
represented.

This tmtable table must have fields year (four
digits), month (1--12), day (1--31),
And may have fields hour (0--23), min (0--59),
sec (0--61), wday (weekday, Sunday is 1),
yday (day of the year), and isdst (daylight
saving flag, a Boolean).
Internally lua convert the tmtable to its
equivalent tm struct.
struct tm {
int tm_sec;        seconds after the minute
(from 0)
int tm_min;        minutes after the hour
(from 0)
int tm_hour;       hour of the day (from 0)
int tm_mday;       day of the month (from
1)
int tm_mon;        month of the year (from
0)
int tm_year;       years since 1900 (from
0)
int tm_wday;       days since Sunday (from
0)
int tm_yday;       day of the year (from 0)
int tm_isdst;      Daylight Saving Time
flag
};
and call mktime(struct tm *tptr) function then
returns the result as a lua number. if the
result is -1 it returns nil

But there is a problem to the tmtable.isdst
table
value
it is limited to two values (nil or false) and
(any Lua value different from false and nil)
if tmtable.isdst is false or nil the tm.isdst =
0
if tmtable.isdst is any Lua value different
from
false and nil the tm.isdst = 1

According to the documentation I read tm.isdst
member can have this value
(a) a positive value if Daylight Saving Time is
in effect. Lua value different from false
and nil
(b) zero if Daylight Saving Time is not in
effect. The false or nil Lua value
(c) a negative value if the status of Daylight
Saving Time is not known (so the target
environment should attempt to determine its
status) . No Lua value representation

The problem is there is no equivalent value
representation for (c).
you have to explicitly specify if Daylight
Saving
Time is in effect.

here is my suggestion
(a) can be represented by true value. Daylight
Saving Time is in effect (tm.isdst = 1)
(b) can be represented by false value only.
Daylight Saving Time is not in effect (tm.isdst

= 0)
(c) can be represented by nil value. The target
environment should attempt to determine its
status (tm.isdst = -1)

the function "getboolfield" in lua liolib.c
does
the conversion from lua Boolean value to c
value
static int getboolfield (lua_State *L, const
char
*key) {
int res;
lua_pushstring(L, key);
lua_gettable(L, -2);
res = lua_toboolean(L, -1);
lua_pop(L, 1);
return res;
}
it can be converted to (rename to
"get_trifield")
static int get_trifield (lua_State *L, const
char
*key) {
int res;
lua_pushstring(L, key);
lua_gettable(L, -2);
switch(lua_type(-1)){
case LUA_TNIL:
res = -1;
break;
case LUA_TBOOLEAN:
res = lua_toboolean(L, -1);/* false=0 true=1
*/
break;
default:
luaL_error(L, "invalid value must be nil,
false
or true");
}
lua_pop(L, 1);
return res;
}

or directly
(a) can be represented by 1 or any positive
number. Daylight Saving Time is in effect
(b) can be represented by 0. Daylight Saving
Time
is not in effect
(c) can be represented by -1 or any negative
number. The target environment should attempt
to determine its status

______________________________________________________
Yahoo! for Good
Watch the Hurricane Katrina Shelter From The Storm concert