From de12caa1e784ba956bcf0e15a3b6efdc3cbe0c13 Mon Sep 17 00:00:00 2001 From: gambas Date: Mon, 9 Apr 2018 18:58:11 +0200 Subject: [PATCH] Fix conversion between dates and their local string representation. [INTERPRETER] * BUG: Fix conversion between dates and their local string representation. * OPT: Little optimization in conversion functions calls. [GB.UTIL] * BUG: Fix Date.ToUnixTime() and Date.FromUnixTime() according to the interpreter fix. --- comp/src/gb.util/.src/Date.module | 7 +++++-- comp/src/gb.util/.src/MMain.module | 6 +----- main/gbx/gbx_date.c | 4 ++-- main/gbx/gbx_exec_loop.c | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/comp/src/gb.util/.src/Date.module b/comp/src/gb.util/.src/Date.module index 0f27bae2a..43dd7d76e 100644 --- a/comp/src/gb.util/.src/Date.module +++ b/comp/src/gb.util/.src/Date.module @@ -3,16 +3,19 @@ Export Private $aDay As String[] Private $aMonth As String[] +Private $dEpoch As Date Public Sub ToUnixTime({Date} As Date) As Long - Return DateDiff(Date(1970, 1, 1), {Date}, gb.Second) - System.TimeZone + If Not $dEpoch Then $dEpoch = DateAdd(Date(1970, 1, 1), gb.Second, - System.TimeZone) + Return DateDiff($dEpoch, {Date}, gb.Second) End Public Sub FromUnixTime(UnixTime As Long) As Date - Return Date(1970, 1, 1) + (System.TimeZone + UnixTime) / 86400 + If Not $dEpoch Then $dEpoch = DateAdd(Date(1970, 1, 1), gb.Second, - System.TimeZone) + Return $dEpoch + UnixTime / 86400 End diff --git a/comp/src/gb.util/.src/MMain.module b/comp/src/gb.util/.src/MMain.module index 904d5e60f..b0a15b1d0 100644 --- a/comp/src/gb.util/.src/MMain.module +++ b/comp/src/gb.util/.src/MMain.module @@ -18,10 +18,6 @@ Public Sub Main() - 'Print MPhonetic_French.Run("des") - - 'Print String.ToPhonetic("12 boulevard des batignolles") - - Print Date.FromUnixTime(0) + Print CStr(CDate("1/1/1970")) End diff --git a/main/gbx/gbx_date.c b/main/gbx/gbx_date.c index 220fda877..537788590 100644 --- a/main/gbx/gbx_date.c +++ b/main/gbx/gbx_date.c @@ -155,7 +155,7 @@ DATE_SERIAL *DATE_split_local(VALUE *value, bool local) nmsec = value->_date.time; if (local && nday > 0) - nmsec += DATE_get_timezone() * 1000; + nmsec -= DATE_get_timezone() * 1000; if (nmsec < 0) { @@ -253,7 +253,7 @@ bool DATE_make_local(DATE_SERIAL *date, VALUE *val, bool local) val->_date.date = nday; val->_date.time = ((date->hour * 60) + date->min) * 60 + date->sec; if (timezone) - val->_date.time -= DATE_get_timezone(); + val->_date.time += DATE_get_timezone(); if (val->_date.time < 0) { diff --git a/main/gbx/gbx_exec_loop.c b/main/gbx/gbx_exec_loop.c index 99cfcb520..0123c56e2 100644 --- a/main/gbx/gbx_exec_loop.c +++ b/main/gbx/gbx_exec_loop.c @@ -2330,7 +2330,7 @@ _SUBR_COMPI: _SUBR_CONV: - VALUE_convert(SP - 1, code & 0x3F); + VALUE_conv(SP - 1, code & 0x3F); goto _NEXT; /*-----------------------------------------------*/