@Test public void createReferences1() { GregorianCalendar cal = new GregorianCalendar(2013, 2, 14, 14, 23, 15); cal.set(GregorianCalendar.MILLISECOND, 123); Instant start = cal.getTime().toInstant(); TimeInterval timeInterval = TimeInterval.between(start, start.plus(Duration.ofSeconds(2))); List<Instant> references = TimeScales.createReferences(timeInterval, new TimePeriod(MILLISECOND, 50)); assertThat(references.size(), equalTo(40)); assertThat(references.get(0), equalTo(create(2013, 3, 14, 14, 23, 15, 150))); assertThat(references.get(1), equalTo(create(2013, 3, 14, 14, 23, 15, 200))); assertThat(references.get(39), equalTo(create(2013, 3, 14, 14, 23, 17, 100))); }
static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; }
TimeScales { static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; } }
TimeScales { static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; }  }
TimeScales { static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; }  static TimeScale linearAbsoluteScale(); }
TimeScales { static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; }  static TimeScale linearAbsoluteScale(); final static int HOUR_FIELD_ID; final static int FIRST_HOUR; final static int DAY_FIELD_ID; final static int FIRST_DAY; final static int WEEK_FIELD_ID; final static int FIRST_WEEK; }