<!DOCTYPE html>
<html data-lt-installed="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="padding-bottom: 1px;">
<p>Hi, Evgeniy!</p>
<p>Thanks for the patch! LGTM</p>
<div class="moz-cite-prefix">Sergey</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 6/29/26 20:21, Evgeniy Temirgaleev
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:dc0883ff18fbb518821e577527c9ed070dcc34de.1782588899.git.e.temirgaleev@tarantool.org">
<pre wrap="" class="moz-quote-pre">From: Mike Pall <mike>
Thanks to Temir Galeev. #1470
(cherry picked from commit 72d2061ae2fa9a5fd45237943f9982baf59435ec)
This patch fixes invalid os.time(t) behavior, when it handles -1 time value
as a fail of the libc mktime() regardless of the errno value.
Temir Galeev:
* added the description and the test for the patch
Part of tarantool/tarantool#12480
---
src/lib_os.c | 3 ++-
.../lj-1470-os-time-epoch-minus-1s.test.lua | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 test/tarantool-tests/lj-1470-os-time-epoch-minus-1s.test.lua
diff --git a/src/lib_os.c b/src/lib_os.c
index ffbc3fdc..f6841357 100644
--- a/src/lib_os.c
+++ b/src/lib_os.c
@@ -242,9 +242,10 @@ LJLIB_CF(os_time)
ts.tm_mon = getfield(L, "month", -1) - 1;
ts.tm_year = getfield(L, "year", -1) - 1900;
ts.tm_isdst = getboolfield(L, "isdst");
+ errno = 0;
t = mktime(&ts);
}
- if (t == (time_t)(-1))
+ if (t == (time_t)(-1) && errno != 0)
lua_pushnil(L);
else
lua_pushnumber(L, (lua_Number)t);
diff --git a/test/tarantool-tests/lj-1470-os-time-epoch-minus-1s.test.lua b/test/tarantool-tests/lj-1470-os-time-epoch-minus-1s.test.lua
new file mode 100644
index 00000000..6b5703e4
--- /dev/null
+++ b/test/tarantool-tests/lj-1470-os-time-epoch-minus-1s.test.lua
@@ -0,0 +1,12 @@
+local tap = require('tap')
+
+-- The test file demonstrates os.time() fail to return -1 time value.
+-- See also: <a class="moz-txt-link-freetext" href="https://github.com/LuaJIT/LuaJIT/issues/1470">https://github.com/LuaJIT/LuaJIT/issues/1470</a>.
+local test = tap.test('lj-1470-os-time-epoch-minus-1s')
+
+test:plan(1)
+
+local minus_1s_time = os.date("*t", -1)
+test:is(os.time(minus_1s_time), -1, 'correct os.time()')
+
+test:done(true)
</pre>
</blockquote>
</body>
<lt-container></lt-container>
</html>