Here you can find the source of getTimeFrame(final Calendar calFrom, final Calendar calTo)
Parameter | Description |
---|---|
calFrom | a parameter |
calTo | a parameter |
public static Vector<Integer> getTimeFrame(final Calendar calFrom, final Calendar calTo)
//package com.java2s; import java.util.Calendar; import java.util.Vector; public class Main { /**/*w w w.j a va2s . c o m*/ * * @param calFrom * @param calTo * @return */ public static Vector<Integer> getTimeFrame(final Calendar calFrom, final Calendar calTo) { assert calFrom != null : "'calFrom' can't be null"; assert calTo != null : "'calTo' can't be null"; int from = calendarToInt(calFrom); int to = calendarToInt(calTo); return getTimeFrame(from, to); } /** * * @param from * @param to * @return */ public static Vector<Integer> getTimeFrame(final int from, final int to) { // Protection assert from != 0 : "'from' can't be 0"; assert to != 0 : "'to' can't be 0"; assert from < to : "'from' must be lesser than 'to'."; int from_yy = from / 10000; int to_yy = to / 10000; // get all years into 'timeframe' starting with 'from_yy' to 'to_yy' Vector<Integer> timeFrame = new Vector<Integer>(); for (int i = 0; from_yy + i <= to_yy; i++) { timeFrame.add(from_yy + i); } return timeFrame; } /** * * @param cal * @return */ public static int calendarToInt(Calendar cal) { int yy = cal.get(Calendar.YEAR); int mm = cal.get(Calendar.MONTH) + 1; int dd = cal.get(Calendar.DATE); return yy * 10000 + mm * 100 + dd; } }