From f5a0a0a2f6cc94c5d437f501e68c57df05918655 Mon Sep 17 00:00:00 2001 From: hengsin Date: Sat, 28 May 2022 16:54:16 +0800 Subject: [PATCH] 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. --- .../servlet/org/compiere/web/AdempiereMonitor.java | 12 +++++++++--- .../src/org/idempiere/test/model/MSchedulerTest.java | 10 +++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java b/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java index 3c3cc1a2bd..0e304a1e21 100644 --- a/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java +++ b/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java @@ -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())) - formatter = formatter.withZone(ZoneId.of(clientInfo.getTimeZone())); - else + if (!Util.isEmpty(clientInfo.getTimeZone())) { + try { + formatter = formatter.withZone(ZoneId.of(clientInfo.getTimeZone())); + } 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)); } diff --git a/org.idempiere.test/src/org/idempiere/test/model/MSchedulerTest.java b/org.idempiere.test/src/org/idempiere/test/model/MSchedulerTest.java index fc427196a0..3708d9945d 100644 --- a/org.idempiere.test/src/org/idempiere/test/model/MSchedulerTest.java +++ b/org.idempiere.test/src/org/idempiere/test/model/MSchedulerTest.java @@ -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,11 +143,11 @@ public class MSchedulerTest extends AbstractTestCase { } finally { if (schedule != null && schedule.get_ID() > 0) schedule.deleteEx(true); - if (!Util.isEmpty(currentTimeZone, true)) { - clientInfo.setTimeZone(currentTimeZone); + clientInfo.setTimeZone(currentTimeZone); + if (clientInfo.is_Changed()) { clientInfo.saveEx(); CacheMgt.get().reset(); - } + } } } }