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.
This commit is contained in:
gambas 2018-04-09 18:58:11 +02:00
parent 80c6f1fca9
commit de12caa1e7
4 changed files with 9 additions and 10 deletions

View file

@ -3,16 +3,19 @@
Export Export
Private $aDay As String[] Private $aDay As String[]
Private $aMonth As String[] Private $aMonth As String[]
Private $dEpoch As Date
Public Sub ToUnixTime({Date} As Date) As Long 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 End
Public Sub FromUnixTime(UnixTime As Long) As Date 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 End

View file

@ -18,10 +18,6 @@
Public Sub Main() Public Sub Main()
'Print MPhonetic_French.Run("des") Print CStr(CDate("1/1/1970"))
'Print String.ToPhonetic("12 boulevard des batignolles")
Print Date.FromUnixTime(0)
End End

View file

@ -155,7 +155,7 @@ DATE_SERIAL *DATE_split_local(VALUE *value, bool local)
nmsec = value->_date.time; nmsec = value->_date.time;
if (local && nday > 0) if (local && nday > 0)
nmsec += DATE_get_timezone() * 1000; nmsec -= DATE_get_timezone() * 1000;
if (nmsec < 0) if (nmsec < 0)
{ {
@ -253,7 +253,7 @@ bool DATE_make_local(DATE_SERIAL *date, VALUE *val, bool local)
val->_date.date = nday; val->_date.date = nday;
val->_date.time = ((date->hour * 60) + date->min) * 60 + date->sec; val->_date.time = ((date->hour * 60) + date->min) * 60 + date->sec;
if (timezone) if (timezone)
val->_date.time -= DATE_get_timezone(); val->_date.time += DATE_get_timezone();
if (val->_date.time < 0) if (val->_date.time < 0)
{ {

View file

@ -2330,7 +2330,7 @@ _SUBR_COMPI:
_SUBR_CONV: _SUBR_CONV:
VALUE_convert(SP - 1, code & 0x3F); VALUE_conv(SP - 1, code & 0x3F);
goto _NEXT; goto _NEXT;
/*-----------------------------------------------*/ /*-----------------------------------------------*/