List of usage examples for org.joda.time Years ZERO
Years ZERO
To view the source code for org.joda.time Years ZERO.
Click Source Link
From source file:net.schweerelos.timeline.model.Timeline.java
License:Open Source License
private void recalculate() { if (start == null || end == null) { logger.warn("recalculating aborted, start and/or end is null"); numSlices = 0;/*from ww w. ja va 2s . c o m*/ return; } Interval interval = new Interval(start, end); if (Years.yearsIn(interval).isGreaterThan(Years.ZERO)) { // make it start at the start of the current increment mode start = start.withDayOfYear(start.dayOfYear().getMinimumValue()); end = end.withDayOfYear(end.dayOfYear().getMaximumValue()); interval = new Interval(start, end); // figure out number of slices numSlices = Years.yearsIn(interval).getYears(); if (start.plusYears(numSlices).isBefore(end)) { numSlices += 1; } // update label extractor sliceLabelExtractor = new SliceLabelExtractor() { @Override public String extractLabel(DateTime from) { return from.year().getAsShortText(); } }; // update increment increment = Years.ONE.toPeriod(); incrementMode = Mode.Years; } else if (Months.monthsIn(interval).isGreaterThan(Months.ZERO)) { // make it start at the start of the current increment mode start = start.withDayOfMonth(start.dayOfMonth().getMinimumValue()); end = end.withDayOfMonth(end.dayOfMonth().getMaximumValue()); interval = new Interval(start, end); numSlices = Months.monthsIn(interval).getMonths(); if (start.plusMonths(numSlices).isBefore(end)) { numSlices += 1; } sliceLabelExtractor = new SliceLabelExtractor() { @Override public String extractLabel(DateTime from) { return from.monthOfYear().getAsShortText(); } }; increment = Months.ONE.toPeriod(); incrementMode = Mode.Months; } else if (Weeks.weeksIn(interval).isGreaterThan(Weeks.ZERO)) { start = start.withDayOfWeek(start.dayOfWeek().getMinimumValue()); end = end.withDayOfWeek(end.dayOfWeek().getMaximumValue()); interval = new Interval(start, end); numSlices = Weeks.weeksIn(interval).getWeeks(); if (start.plusWeeks(numSlices).isBefore(end)) { numSlices += 1; } sliceLabelExtractor = new SliceLabelExtractor() { @Override public String extractLabel(DateTime from) { return "W" + from.weekOfWeekyear().getAsShortText(); } }; increment = Weeks.ONE.toPeriod(); incrementMode = Mode.Weeks; } else { numSlices = Days.daysIn(interval).getDays(); if (start.plusDays(numSlices).isBefore(end)) { numSlices += 1; } if (numSlices == 0) { // force at least one day to be drawn numSlices = 1; } sliceLabelExtractor = new SliceLabelExtractor() { @Override public String extractLabel(DateTime from) { return from.dayOfMonth().getAsShortText(); } }; increment = Days.ONE.toPeriod(); incrementMode = Mode.Days; } // reset time of day too start = start.withMillisOfDay(start.millisOfDay().getMinimumValue()); end = end.withMillisOfDay(end.millisOfDay().getMaximumValue()); // recalculate which intervals are within range intervalsWithinRange.clear(); intervalsWithinRange.addAll(calculateIntervalsWithinRange(start, end)); // notify listeners changeSupport.firePropertyChange(INTERVAL_PROPERTY_KEY, interval, new Interval(start, end)); }