I have a spring-boot scheduler that wakes up every 15 minutes. It is a cron, so it will always wake up around proper boundary with some jitter but is usually around 00
, 15
, 30
, 45
, 60
.
I need to do the below:
- Do some action
A
for 30 minute boundary only if at wakeup, delta is within 3 minute range on either side. So around11:00am
do actionA
only if time is around10:57-11:03
. Similar for the30
minute boundary, do it if delta is around10:57-11:03
or11:27-11:33
I am reading time as below when scheduler wakes up
ZonedDateTime currentDate = (ZonedDateTime.now(ZoneOffset.UTC).truncatedTo(ChronoUnit.MINUTES));
ZonedDateTime prior = currentDate.minus(3,ChronoUnit.MINUTES);
ZonedDateTime next = currentDate.plus(3,ChronoUnit.MINUTES);
I am familiar I can add and subtract to get the window as above. But where I am getting lost is the trivial part of how do I compare of the time is within the prior and next boundary?
Because if the scheduler woke up at 11:35, I do not wish to take the action for 11:30 and skip processing.