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 ""; return "";
DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
MClientInfo clientInfo = MClientInfo.get(AD_Client_ID); MClientInfo clientInfo = MClientInfo.get(AD_Client_ID);
if (!Util.isEmpty(clientInfo.getTimeZone())) if (!Util.isEmpty(clientInfo.getTimeZone())) {
formatter = formatter.withZone(ZoneId.of(clientInfo.getTimeZone())); try {
else formatter = formatter.withZone(ZoneId.of(clientInfo.getTimeZone()));
} catch (Exception e) {
//fallback to default
formatter = formatter.withZone(ZoneId.systemDefault());
}
} else {
formatter = formatter.withZone(ZoneId.systemDefault()); formatter = formatter.withZone(ZoneId.systemDefault());
}
return formatter.format(date.toInstant().truncatedTo(ChronoUnit.SECONDS)); return formatter.format(date.toInstant().truncatedTo(ChronoUnit.SECONDS));
} }

View File

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