diff --git a/changelog.md b/changelog.md index bc595dcce..513a1a570 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ ## Fixes/improvements +* [#3621] Fix `os.time()` being off by one hour * [#3682] Add error handling to the `flash` OpenOS program * [#3764] Fix left and right names being swapped in the Rack GUI * [#3779] Fix `os.sleep(0)` causing `too long without yielding` (Ocawesome101) diff --git a/src/main/scala/li/cil/oc/server/machine/luac/OSAPI.scala b/src/main/scala/li/cil/oc/server/machine/luac/OSAPI.scala index 56773404f..9d539f356 100644 --- a/src/main/scala/li/cil/oc/server/machine/luac/OSAPI.scala +++ b/src/main/scala/li/cil/oc/server/machine/luac/OSAPI.scala @@ -67,10 +67,11 @@ class OSAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) { if (lua.isNoneOrNil(1)) { // Game time is in ticks, so that each day has 24000 ticks, meaning // one hour is game time divided by one thousand. Also, Minecraft - // starts days at 6 o'clock, versus the 1 o'clock of timestamps so we - // add those five hours. Thus: - // timestamp = (time + 5000) * 60[kh] * 60[km] / 1000[s] - lua.pushNumber(((machine.worldTime + 5000) * 60 * 60) / 1000.0) + // starts days at 6 o'clock; os.time() reflects UTC while os.date() + // reflects the local time zone, but Minecraft has no concept of + // time zones, so this detail can be ignored. Thus: + // timestamp = (time + 6000) * 60[kh] * 60[km] / 1000[s] + lua.pushNumber(((machine.worldTime + 6000) * 60 * 60) / 1000.0) } else { def getField(key: String, d: Int) = { diff --git a/src/main/scala/li/cil/oc/server/machine/luaj/OSAPI.scala b/src/main/scala/li/cil/oc/server/machine/luaj/OSAPI.scala index 06e721194..41b3e0e39 100644 --- a/src/main/scala/li/cil/oc/server/machine/luaj/OSAPI.scala +++ b/src/main/scala/li/cil/oc/server/machine/luaj/OSAPI.scala @@ -51,10 +51,11 @@ class OSAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) { if (args.isnoneornil(1)) { // Game time is in ticks, so that each day has 24000 ticks, meaning // one hour is game time divided by one thousand. Also, Minecraft - // starts days at 6 o'clock, versus the 1 o'clock of timestamps so we - // add those five hours. Thus: - // timestamp = (time + 5000) * 60[kh] * 60[km] / 1000[s] - LuaValue.valueOf((machine.worldTime + 5000) * 60 * 60 / 1000) + // starts days at 6 o'clock; os.time() reflects UTC while os.date() + // reflects the local time zone, but Minecraft has no concept of + // time zones, so this detail can be ignored. Thus: + // timestamp = (time + 6000) * 60[kh] * 60[km] / 1000[s] + LuaValue.valueOf((machine.worldTime + 6000) * 60 * 60 / 1000) } else { val table = args.checktable(1)