RealtimeBarUtil { public static Date getFirstScheduledDate(Date date, int interval) { LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); ldt = ldt.withNano(0).withSecond(0).plusMinutes(1); while (ldt.getMinute() % interval != 0) { ldt = ldt.plusMinutes(1); } return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); }  static JobDetail buildJob(String jobName, IBarBuilder barBuilder); static Trigger getTrigger(String jobName, int interval, LengthUnit units); static Date getFirstScheduledDate(Date date, int interval); static String getJobName(RealtimeBarRequest realtimeBarRequest); static LocalDateTime getBarDate(); static final String BAR_BUILDER_DATA; }
@Test public void testGetFirstScheduledDate() { int interval = 1; Date date = new Date(); LocalDateTime expected = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); expected = expected.withNano(0).withSecond(0).plusMinutes(1); while (expected.getMinute() % interval != 0) { expected = expected.plusMinutes(1); } assertEquals(Date.from(expected.atZone(ZoneId.systemDefault()).toInstant()), RealtimeBarUtil.getFirstScheduledDate(date, interval)); }
@Test public void testGetFirstScheduledDate_60MinuteBar() { int interval = 60; Date date = new Date(); GregorianCalendar expected = new GregorianCalendar(); expected.setTime(date); expected.set(Calendar.MILLISECOND, 0); expected.set(Calendar.SECOND, 0); expected.add(Calendar.MINUTE, 1); expected.set( Calendar.MINUTE, 0 ); expected.add( Calendar.HOUR, 1); assertEquals(expected.getTime(), RealtimeBarUtil.getFirstScheduledDate(date, interval)); }