All the right offsets in all the wrong places. Should fix #1278.

mktime is still borked kinda, but cba to fix that now ._.
This commit is contained in:
Florian Nücke 2015-07-11 17:06:16 +02:00
parent b7ae7554fc
commit f71bf06a59
3 changed files with 6 additions and 7 deletions

View File

@ -25,7 +25,7 @@ class OSAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
else "%d/%m/%y %H:%M:%S" else "%d/%m/%y %H:%M:%S"
val time = val time =
if (lua.getTop > 1 && lua.isNumber(2)) lua.toNumber(2) * 1000 / 60 / 60 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) val dt = GameTimeFormatter.parse(time)
def fmt(format: String) { def fmt(format: String) {

View File

@ -18,7 +18,7 @@ class OSAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) {
else "%d/%m/%y %H:%M:%S" else "%d/%m/%y %H:%M:%S"
val time = val time =
if (args.narg > 1 && args.isnumber(2)) args.todouble(2) * 1000 / 60 / 60 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) val dt = GameTimeFormatter.parse(time)
def fmt(format: String) = { def fmt(format: String) = {

View File

@ -67,8 +67,8 @@ object GameTimeFormatter {
def parse(time: Double) = { def parse(time: Double) = {
var day = (time / 24000).toLong var day = (time / 24000).toLong
val weekDay = ((4 + day) % 7).toInt val weekDay = ((4 + day) % 7).toInt
val year = 1970 + (day / 365.2425).toInt val year = 1970 + (day / 364.2425).toInt
val yearDay = (day % 365.2425).toInt val yearDay = (day % 364.2425).toInt
day = yearDay day = yearDay
val monthLengths = monthLengthsForYear(year) val monthLengths = monthLengthsForYear(year)
var month = 0 var month = 0
@ -80,7 +80,7 @@ object GameTimeFormatter {
var seconds = ((time % 24000) * 60 * 60 / 1000).toInt var seconds = ((time % 24000) * 60 * 60 / 1000).toInt
var minutes = seconds / 60 var minutes = seconds / 60
seconds = seconds % 60 seconds = seconds % 60
val hours = (1 + minutes / 60) % 24 val hours = (minutes / 60) % 24
minutes = minutes % 60 minutes = minutes % 60
new DateTime(year, month + 1, day.toInt + 1, weekDay + 1, yearDay + 1, hours, minutes, seconds) 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 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 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 val secs = sec + (min + (hour - 1 + days * 24) * 60) * 60
if (secs < 0) None Option(secs)
else Option(secs)
} }
} }