Date is subtracted by 1 day in certain cases

Description

Documenting here two reports that I have found about this case.

First is this thread:
https://groups.google.com/g/idempiere/c/lE3gRDFXATU/m/PYVyG0BkBQAJ

In that thread I did some tests and showed some cases failing.
Some of my comment there:

From my debug session going very very deep in the problem I noticed when I fill the datebox with 07201810 - the value passed through zk is something like "1810.7.20.4.56.16.0" - so until some point the string is still july-20.
Then it arrives to org.zkoss.zk.au.AuRequest->parseType - line 108 (breakpoint here)
This calls org.zkoss.json.JSONs->j2d
and there the string is converted to a date with july-19

A bit more of research on this, found:
https://tracker.zkoss.org/browse/ZK-3527

This commit made a change on the timezone on JSONs (changed from zk
version 8.0 to 8.5)
https://github.com/zkoss/zk/commit/222d17d

Probably we need to adapt our code to that change.

______________

Yesterday I received the second report about this - easily reproducible.

If the server is on timezone America/Sao_Paulo the same issue happens with dates >= Oct-21/2019

Environment can be simulated adding this parameter in eclipse or to the IDEMPIERE_JAVA_OPTIONS in server:

In mattermost chat
https://mattermost.idempiere.org/idempiere/pl/g5wifuiodiy8z8qu76us8mw4oa
pointed to the solution of this issue. Changing the timezone to GMT-3 works, that is probably caused because Brazil changed the daylight and timezone in 2019.

Setting the breakpoint in the same line org.zkoss.zk.au.AuRequest->parseType:108 leads to the same conclusion.

Environment

None

Activity

Show:
Carlos Ruiz
September 1, 2020, 2:22 PM

Researching more about this issue found this answer here:
https://stackoverflow.com/a/32281019/1968443

And as a "workaround" if we can call it that way, I tested setting the -Duser.timezone=UTC and everything works fine in UTC, I suppose because there are no conversions between timezones.

Added some notes on to think further about this possibility.

Hiep Lq
September 1, 2020, 3:44 PM

> is there a way to know which timezone/offset is javascript using and adjust the java code to use the same offset when converting back?

java time library use database from https://www.iana.org/time-zones
i guess zk javascript also same, because other case get correct and same offset for both side

i saw that data on this file https://github.com/zkoss/zk/blob/master/zk/src/archive/web/js/zk/ext/moment-timezone-with-data.js

it said "version": "2019a". it's same my jdk-13 but i still get error (as i know you use update jdk-11 and version = "2019c")

> I tested setting the -Duser.timezone=UTC and everything works fine in UTC, I suppose because there are no conversions between timezones.

i test this way on fist place, but it seem not safe

  1. old value on database maybe not sync, because getTime of UTC (new data) is difference by getTime of default timezone (old data)

  2. at moment idempiere don't support multi timezone at webui but it can improve to support, this workaround void this improve

i will study moment-timezone-with-data.js to see why offset on date 03/28/2500 is difference

Hiep Lq
September 2, 2020, 11:03 PM

root course by Moment library https://github.com/moment/moment-timezone/issues/891

from year 2500 will get that error, because we know point of time get error can adjust (when read from database) as workaround
but it's not sure for other timezone

Hiep Lq
September 2, 2020, 11:07 PM
Edited
Carlos Ruiz
September 5, 2020, 9:05 AM

Thanks , I merged the pull request as it solves half of the problem.

I see the other half is a bug in a javascript library, so, let's keep this open.

About my two ideas above:

is there a way to know which timezone/offset is javascript using and adjust the java code to use the same offset when converting back?

If I understood this right - java and javascript are using the same timezone, but as the libraries are different a mismatch on one side creates bad date on the other side, and you found and reported a bug in the javascript library moment-timezone.

is there a way to set Datebox or to indicate javascript to not use timezone at all, so we do the calculations (if required) just in java.

I tried this approach too, setting the timezone in UTC for the Datebox on WDateEditor and WDatetimeEditor.
The problem is that the zk class for Datebox uses an object of type Date to save the value - Date object in java doesn't have timezone information, it uses the default timezone.
A possible solution would be to implement a Datebox zk version that uses ZonedDateTime class instead of Date, but that's something must be solved in zk side I guess.

Having a ZonedDateTime would make possible to have a Datebox in UTC and that would avoid the timezone mismatch, and the conversion would be done just in java in WDateEditor side.

I think we can keep this on hold as a valid workaround was found, although is not the most useful for everybody.

Regards,

Carlos Ruiz

Assignee

Hiep Lq

Reporter

Carlos Ruiz

Labels

None

Tested By

None

Priority

Major
Configure