Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Added delay of 1 second if range events are scheduled at same instant
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Kumar Mondal <admin@amitinside.com>
  • Loading branch information
amitjoy committed Jun 27, 2017
1 parent 04a064c commit 8670894
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Expand Up @@ -7,6 +7,7 @@
*/
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.eclipse.smarthome.binding.astro.AstroBindingConstants.*;
Expand Down Expand Up @@ -39,7 +40,7 @@ public interface Job extends Runnable {

/** Logger Instance */
public final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

/**
* Schedules the provided {@link Job} instance
*
Expand Down Expand Up @@ -111,8 +112,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);
}

/**
Expand Down
Expand Up @@ -167,7 +167,7 @@ public static boolean isTimeGreaterEquals(Calendar cal1, Calendar cal2) {
Calendar truncCal2 = DateUtils.truncate(cal2, Calendar.MINUTE);
return truncCal1.getTimeInMillis() >= truncCal2.getTimeInMillis();
}

/**
* Applies the config to the given calendar.
*/
Expand Down

0 comments on commit 8670894

Please sign in to comment.