public CoordinateRuntime(List<Long> runtimeSorted, CalendarPeriod timeUnit) { this.runtimes = new long[runtimeSorted.size()]; int idx = 0; for (long val : runtimeSorted) this.runtimes[idx++] = val; this.firstDate = CalendarDate.of(runtimeSorted.get(0)); this.timeUnit = timeUnit == null ? CalendarPeriod.Hour : timeUnit; CalendarPeriod.Field cf = this.timeUnit.getField(); if (cf == CalendarPeriod.Field.Month || cf == CalendarPeriod.Field.Year) this.periodName = "calendar "+ cf.toString(); else this.periodName = cf.toString(); }
public String getTimeIntervalName() { if (!isInterval()) return null; // are they the same length ? int firstValue = -1; boolean same = true; for (Tinv tinv : intervals) { int value = (tinv.b2 - tinv.b1); if (firstValue < 0) firstValue = value; else if (value != firstValue) same = false; } if (same) { firstValue = (firstValue * calendarPeriod.getValue()); return firstValue + "_" + calendarPeriod.getField().toString(); } else { return CoordinateTimeAbstract.MIXED_INTERVALS; } }
/** * Check if we all time intervals have the same length. * @return time interval name or MIXED_INTERVALS */ public String getTimeIntervalName() { // are they the same length ? int firstValue = -1; for (TimeCoord.Tinv tinv : timeIntervals) { int value = (tinv.getBounds2() - tinv.getBounds1()); if (firstValue < 0) firstValue = value; else if (value != firstValue) return MIXED_INTERVALS; } firstValue = (firstValue * timeUnit.getValue()); return firstValue + "_" + timeUnit.getField().toString(); }
CoordinateTimeAbstract(int code, CalendarPeriod timeUnit, CalendarDate refDate, int[] time2runtime) { this.code = code; this.timeUnit = timeUnit; this.refDate = (cdf == null) ? refDate : cdf.get(refDate); this.time2runtime = time2runtime; CalendarPeriod.Field cf = timeUnit.getField(); if (cf == CalendarPeriod.Field.Month || cf == CalendarPeriod.Field.Year) this.periodName = "calendar "+ cf.toString(); else this.periodName = cf.toString(); }
public String getUnits() { if (units != null) return units; CalendarPeriod.Field cf = calendarPeriod.getField(); if (cf == CalendarPeriod.Field.Month || cf == CalendarPeriod.Field.Year) return "calendar "+ cf.toString() + " since " + runDate; else return calendarPeriod.getField().toString() + " since " + runDate; }
/** * String representation * @return getText() */ public String toString() { return timeUnit.toString(); }
private void assertAddReturnsExpectedDate(String baseDate, double value, Field units, String expectedResult) { CalendarDate base = CalendarDateFormatter.isoStringToCalendarDate(Calendar.gregorian, baseDate); CalendarDate result = base.add(value, units); assertEquals(units.toString(), expectedResult, CalendarDateFormatter.toDateTimeStringISO(result)); }
/** * String representation * @return getText() */ public String toString() { return timeUnit.toString(); }
private CalendarDateUnit(Calendar calt, CalendarPeriod.Field periodField, CalendarDate baseDate) { this.cal = calt; this.periodField = periodField; this.baseDate = baseDate; String periodName; if (periodField == CalendarPeriod.Field.Month || periodField == CalendarPeriod.Field.Year) { periodName = "calendar "+ periodField.toString(); isCalendarField = true; } else { periodName = periodField.toString(); isCalendarField = false; } unitString = periodName + " since " + baseDate.toString(); }
/** * Get the String text * @return the text */ public String getText() { return text == null ? timeUnit.toString() : text; }