IDEMPIERE-5093 Scheduler cron pattern scheduling is always using server time zone (#1348)

- Fix unit test.
- Fix server monitor error out if AD_ClientInfo.TimeZone has invalid
value.
This commit is contained in:
hengsin 2022-05-28 16:54:16 +08:00 committed by GitHub
parent ad7f78e3c1
commit f5a0a0a2f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -926,10 +926,16 @@ public class AdempiereMonitor extends HttpServlet
return "";
DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
MClientInfo clientInfo = MClientInfo.get(AD_Client_ID);
if (!Util.isEmpty(clientInfo.getTimeZone()))
if (!Util.isEmpty(clientInfo.getTimeZone())) {
try {
formatter = formatter.withZone(ZoneId.of(clientInfo.getTimeZone()));
else
} catch (Exception e) {
//fallback to default
formatter = formatter.withZone(ZoneId.systemDefault());
}
} else {
formatter = formatter.withZone(ZoneId.systemDefault());
}
return formatter.format(date.toInstant().truncatedTo(ChronoUnit.SECONDS));
}

View File

@ -94,7 +94,7 @@ public class MSchedulerTest extends AbstractTestCase {
cal2.setTimeZone(tz2);
cal2.setTimeInMillis(System.currentTimeMillis());
hour = cal2.get(Calendar.HOUR_OF_DAY);
if (hour > 17) {
if (hour >= 17) {
cal2.add(Calendar.DAY_OF_MONTH, 1);
}
cal2.set(Calendar.HOUR_OF_DAY, 17);
@ -126,7 +126,7 @@ public class MSchedulerTest extends AbstractTestCase {
assertFalse(cal2.getTimeInMillis() == ts1.getTime(), "Un-expected date next run");
//test with default + 2hour time zone
clientInfo.setTimeZone(tz2.getID());
clientInfo.setTimeZone(tz2.toZoneId().getId());
clientInfo.saveEx();
CacheMgt.get().reset();
@ -143,8 +143,8 @@ public class MSchedulerTest extends AbstractTestCase {
} finally {
if (schedule != null && schedule.get_ID() > 0)
schedule.deleteEx(true);
if (!Util.isEmpty(currentTimeZone, true)) {
clientInfo.setTimeZone(currentTimeZone);
if (clientInfo.is_Changed()) {
clientInfo.saveEx();
CacheMgt.get().reset();
}