From 5bc2741823f262ca46bee1647335f8359f8df99f Mon Sep 17 00:00:00 2001 From: Amit Kumar Mondal Date: Tue, 27 Jun 2017 13:03:07 +0200 Subject: [PATCH] Added delay of 1 second if range events are scheduled at same instant Signed-off-by: Amit Kumar Mondal --- .../smarthome/binding/astro/internal/job/Job.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/extensions/binding/org.eclipse.smarthome.binding.astro/src/main/java/org/eclipse/smarthome/binding/astro/internal/job/Job.java b/extensions/binding/org.eclipse.smarthome.binding.astro/src/main/java/org/eclipse/smarthome/binding/astro/internal/job/Job.java index 6c805a82051..ffc4d59ddbe 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.astro/src/main/java/org/eclipse/smarthome/binding/astro/internal/job/Job.java +++ b/extensions/binding/org.eclipse.smarthome.binding.astro/src/main/java/org/eclipse/smarthome/binding/astro/internal/job/Job.java @@ -7,8 +7,10 @@ */ package org.eclipse.smarthome.binding.astro.internal.job; +import static java.util.Calendar.SECOND; import static java.util.Objects.isNull; import static org.apache.commons.lang.time.DateFormatUtils.ISO_DATETIME_FORMAT; +import static org.apache.commons.lang.time.DateUtils.truncatedEquals; import static org.eclipse.smarthome.binding.astro.AstroBindingConstants.*; import static org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils.*; import static org.eclipse.smarthome.core.scheduler.CronHelper.createCronFromCalendar; @@ -111,8 +113,15 @@ public static void scheduleRange(String thingUID, AstroThingHandler astroHandler if (thingNull || astroHandlerNull || rangeNull || channelIdNull) { return; } - scheduleEvent(thingUID, astroHandler, range.getStart(), EVENT_START, channelId); - scheduleEvent(thingUID, astroHandler, range.getEnd(), EVENT_END, channelId); + + //add 1 second to the last scheduled event if both the events comprise same time instant + Calendar start = range.getStart(); + Calendar end = range.getEnd(); + if (truncatedEquals(start, end, SECOND)) { + end.add(SECOND, 1); + } + scheduleEvent(thingUID, astroHandler, start, EVENT_START, channelId); + scheduleEvent(thingUID, astroHandler, end, EVENT_END, channelId); } /**