Java Calendar Time getTimeFrame(final Calendar calFrom, final Calendar calTo)

Here you can find the source of getTimeFrame(final Calendar calFrom, final Calendar calTo)

Description

get Time Frame

License

GNU General Public License

Parameter

Parameter Description
calFrom a parameter
calTo a parameter

Declaration

public static Vector<Integer> getTimeFrame(final Calendar calFrom, final Calendar calTo) 

Method Source Code

//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;

    }
}

Related

  1. getMaxTimeCalendar(Calendar source)
  2. getTime(Calendar c)
  3. getTime(Calendar c)
  4. getTime(Calendar cal)
  5. getTime(Date date, int CalendarType, int interval)
  6. getTimeInHHMMSS(Calendar time)
  7. getTimeStr(Calendar cal)
  8. getTimeToString(Calendar argCal)
  9. getTimeValue(Calendar cal)