由于 2038 年问题(<a href="https://en.wikipedia.org/wiki/Year_2038_problem" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Year_2038_problem),我们在 32 位机器上调用 os.time({year=2039, month=1, day=1, hour=0, sec=1}) 后得到 nil。如何使其在 lua 层兼容,并得到类似的结果在 64 位机器上运行?编写如下函数是否可行?否则怎么实现呢?
local function time32Compatibility(timeTable)
local kMaxYearIn32Bit = 2037;
if timeTable and timeTable.year and timeTable.year >= kMaxYearIn32Bit then
local originalTable = clone(timeTable);
timeTable.year = kMaxYearIn32Bit;
local deltaTime = calculateDeltaTime(timeTable,originalTable)
return os.time(timeTable) + kMaxYearIn32Bit*;
else
return os.time(timeTable);
end
end
如何编写calculateDeltaTime()?