Skip to content

Commit a31f90a

Browse files
committed
fix #3621
1 parent 5d35d7f commit a31f90a

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Fixes/improvements
22

3+
* [#3621] Fix `os.time()` being off by one hour
34
* [#3682] Add error handling to the `flash` OpenOS program
45
* [#3764] Fix left and right names being swapped in the Rack GUI
56
* [#3779] Fix `os.sleep(0)` causing `too long without yielding` (Ocawesome101)

src/main/scala/li/cil/oc/server/machine/luac/OSAPI.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ class OSAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
6767
if (lua.isNoneOrNil(1)) {
6868
// Game time is in ticks, so that each day has 24000 ticks, meaning
6969
// one hour is game time divided by one thousand. Also, Minecraft
70-
// starts days at 6 o'clock, versus the 1 o'clock of timestamps so we
71-
// add those five hours. Thus:
72-
// timestamp = (time + 5000) * 60[kh] * 60[km] / 1000[s]
73-
lua.pushNumber(((machine.worldTime + 5000) * 60 * 60) / 1000.0)
70+
// starts days at 6 o'clock; os.time() reflects UTC while os.date()
71+
// reflects the local time zone, but Minecraft has no concept of
72+
// time zones, so this detail can be ignored. Thus:
73+
// timestamp = (time + 6000) * 60[kh] * 60[km] / 1000[s]
74+
lua.pushNumber(((machine.worldTime + 6000) * 60 * 60) / 1000.0)
7475
}
7576
else {
7677
def getField(key: String, d: Int) = {

src/main/scala/li/cil/oc/server/machine/luaj/OSAPI.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ class OSAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) {
5151
if (args.isnoneornil(1)) {
5252
// Game time is in ticks, so that each day has 24000 ticks, meaning
5353
// one hour is game time divided by one thousand. Also, Minecraft
54-
// starts days at 6 o'clock, versus the 1 o'clock of timestamps so we
55-
// add those five hours. Thus:
56-
// timestamp = (time + 5000) * 60[kh] * 60[km] / 1000[s]
57-
LuaValue.valueOf((machine.worldTime + 5000) * 60 * 60 / 1000)
54+
// starts days at 6 o'clock; os.time() reflects UTC while os.date()
55+
// reflects the local time zone, but Minecraft has no concept of
56+
// time zones, so this detail can be ignored. Thus:
57+
// timestamp = (time + 6000) * 60[kh] * 60[km] / 1000[s]
58+
LuaValue.valueOf((machine.worldTime + 6000) * 60 * 60 / 1000)
5859
}
5960
else {
6061
val table = args.checktable(1)

0 commit comments

Comments
 (0)