From f71bf06a5995e7c1f1cae4743fc65b6d26420f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 11 Jul 2015 17:06:16 +0200 Subject: [PATCH] All the right offsets in all the wrong places. Should fix #1278. mktime is still borked kinda, but cba to fix that now ._. --- src/main/scala/li/cil/oc/server/machine/luac/OSAPI.scala | 2 +- src/main/scala/li/cil/oc/server/machine/luaj/OSAPI.scala | 2 +- src/main/scala/li/cil/oc/util/GameTimeFormatter.scala | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) 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 94047e9ee..6ae6d04bf 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 @@ -25,7 +25,7 @@ class OSAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) { else "%d/%m/%y %H:%M:%S" val time = if (lua.getTop > 1 && lua.isNumber(2)) lua.toNumber(2) * 1000 / 60 / 60 - else machine.worldTime + 5000 + else machine.worldTime + 6000 val dt = GameTimeFormatter.parse(time) def fmt(format: String) { 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 439e74057..b0050abc7 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 @@ -18,7 +18,7 @@ class OSAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) { else "%d/%m/%y %H:%M:%S" val time = if (args.narg > 1 && args.isnumber(2)) args.todouble(2) * 1000 / 60 / 60 - else machine.worldTime + 5000 + else machine.worldTime + 6000 val dt = GameTimeFormatter.parse(time) def fmt(format: String) = { diff --git a/src/main/scala/li/cil/oc/util/GameTimeFormatter.scala b/src/main/scala/li/cil/oc/util/GameTimeFormatter.scala index c72e37b85..fe57294e3 100644 --- a/src/main/scala/li/cil/oc/util/GameTimeFormatter.scala +++ b/src/main/scala/li/cil/oc/util/GameTimeFormatter.scala @@ -67,8 +67,8 @@ object GameTimeFormatter { def parse(time: Double) = { var day = (time / 24000).toLong val weekDay = ((4 + day) % 7).toInt - val year = 1970 + (day / 365.2425).toInt - val yearDay = (day % 365.2425).toInt + val year = 1970 + (day / 364.2425).toInt + val yearDay = (day % 364.2425).toInt day = yearDay val monthLengths = monthLengthsForYear(year) var month = 0 @@ -80,7 +80,7 @@ object GameTimeFormatter { var seconds = ((time % 24000) * 60 * 60 / 1000).toInt var minutes = seconds / 60 seconds = seconds % 60 - val hours = (1 + minutes / 60) % 24 + val hours = (minutes / 60) % 24 minutes = minutes % 60 new DateTime(year, month + 1, day.toInt + 1, weekDay + 1, yearDay + 1, hours, minutes, seconds) @@ -107,7 +107,6 @@ object GameTimeFormatter { val monthLengths = monthLengthsForYear(year) val days = ((year - 1970) * 365.2425).ceil.toInt + (0 until mon - 1).foldLeft(0)((d, m) => d + monthLengths(m)) + mday - 1 val secs = sec + (min + (hour - 1 + days * 24) * 60) * 60 - if (secs < 0) None - else Option(secs) + Option(secs) } }