lua-users home
lua-l archive

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


Hello,

In Lua 5.1, when you call os.date with an empty format string, you get
the somewhat unexpected error "'date' format too long" :-)

This is because the implementation checks the return value from the C
function strftime() which is 0 both when there is an error and when
the format string is empty.

This is not critical, but one would expect os.date to return the empty
string when the format is empty (just like string.format). A possible
fix would be:

--- loslib.c
+++ loslib.c
@@ -145,6 +145,8 @@
    setfield(L, "yday", stm->tm_yday+1);
    setboolfield(L, "isdst", stm->tm_isdst);
  }
+  else if (*s == '\0')
+    lua_pushstring(L, "");
  else {
    char b[256];
    if (strftime(b, sizeof(b), s, stm))

--
Julien Cugnière