Example usage for java.util Calendar DECEMBER

List of usage examples for java.util Calendar DECEMBER

Introduction

In this page you can find the example usage for java.util Calendar DECEMBER.

Prototype

int DECEMBER

To view the source code for java.util Calendar DECEMBER.

Click Source Link

Document

Value of the #MONTH field indicating the twelfth month of the year in the Gregorian and Julian calendars.

Usage

From source file:gbc.jtimecalc.AbstractTimeDifferenceCalculatorTest.java

public void shouldReturn2Months3Days0Hours0Minutes0seconds() {
    Calendar end = prepareCalendar(2006, Calendar.FEBRUARY, 1, 0, 0, 0, 0);
    // 1.02.2006 00:00:00.0
    setEndTime(end.getTimeInMillis());//from w w  w. j a v a  2  s  .c o m

    Calendar start = (Calendar) end.clone();
    start.set(Calendar.MONTH, Calendar.DECEMBER);
    start.set(Calendar.YEAR, 2005);
    // 1.12.2005 00:00:00.0

    setStartTime(start.getTimeInMillis());
    expectedValue = messages.get("2Months3Days");
}

From source file:cs.umass.edu.prepare.view.activities.CalendarActivity.java

/**
 * Changes the activity_calendar to display the next month.
 *//* ww w . ja  v  a 2s.co  m*/
private void nextMonth() {
    int month = this.month.get(Calendar.MONTH);
    int year = this.month.get(Calendar.YEAR);
    if (month == Calendar.DECEMBER) {
        this.month.set(year + 1, Calendar.JANUARY, 1);
    } else {
        this.month.set(Calendar.MONTH, month + 1);
    }
    refreshCalendar();
}

From source file:org.jfree.data.time.Week.java

/**
 * Returns the week following this one.  This method will return
 * <code>null</code> for some upper limit on the range of weeks (currently
 * week 53, 9999).  For week 52 of any year, the following week is always
 * week 53, but week 53 may not contain any days (you should check for
 * this).//ww  w  .  j a  v  a2  s.  c o m
 *
 * @return The following week (possibly <code>null</code>).
 */
@Override
public RegularTimePeriod next() {

    Week result;
    if (this.week < 52) {
        result = new Week(this.week + 1, this.year);
    } else {
        Calendar calendar = Calendar.getInstance();
        calendar.set(this.year, Calendar.DECEMBER, 31);
        int actualMaxWeek = calendar.getActualMaximum(Calendar.WEEK_OF_YEAR);
        if (this.week < actualMaxWeek) {
            result = new Week(this.week + 1, this.year);
        } else {
            if (this.year < 9999) {
                result = new Week(FIRST_WEEK_IN_YEAR, this.year + 1);
            } else {
                result = null;
            }
        }
    }
    return result;

}

From source file:cs.umass.edu.prepare.view.activities.CalendarActivity.java

/**
 * Changes the activity_calendar to show the previous month.
 *//*from   w  w w  . j  ava  2s.  c  o m*/
private void previousMonth() {
    int month = this.month.get(Calendar.MONTH);
    int year = this.month.get(Calendar.YEAR);
    if (month == Calendar.JANUARY) {
        this.month.set(year - 1, Calendar.DECEMBER, 1);
    } else {
        this.month.set(Calendar.MONTH, month - 1);
    }
    refreshCalendar();
}

From source file:com.flattr4android.rest.FlattrRestClient.java

public ArrayList<Click> getMyClicks(Date startDate, Date stopDate)
        throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException,
        FlattrServerResponseException, FlattrRestException, IOException {
    ArrayList<Click> clicks = new ArrayList<Click>();
    Calendar cal = Calendar.getInstance();
    cal.setTime(startDate);/*from  w w w.  j  av  a  2  s. c  o  m*/
    int startYear = cal.get(Calendar.YEAR);
    int startMonth = cal.get(Calendar.MONTH);
    int startDay = cal.get(Calendar.DAY_OF_MONTH);

    cal.setTime(stopDate);
    int stopYear = cal.get(Calendar.YEAR);
    int stopMonth = cal.get(Calendar.MONTH);
    int stopDay = cal.get(Calendar.DAY_OF_MONTH);

    int currentYear = startYear;
    int currentMonth = startMonth;
    Calendar currentClickDate = Calendar.getInstance();

    while ((currentYear < stopYear) || ((currentYear == stopYear) && (currentMonth <= stopMonth))) {
        String period = Integer.toString(currentYear * 100 + (currentMonth + 1));
        ArrayList<Click> current = getMyClicks(period);
        // If we are in the first month of the interval,
        // be careful not to add clicks too early in the month.
        boolean checkLow = ((currentYear == startYear) && (currentMonth == startMonth));
        boolean checkHigh = ((currentYear == stopYear) && (currentMonth == stopMonth));
        if ((!checkLow) && (!checkHigh)) {
            // Clicks in the middle of the interval: add all!
            clicks.addAll(current);
        } else {
            // Check one by one
            for (Click click : current) {
                currentClickDate.setTime(click.getDate());
                int currentDay = currentClickDate.get(Calendar.DAY_OF_MONTH);
                if (((!checkLow) || (currentDay >= startDay)) && ((!checkHigh) || (currentDay <= stopDay))) {
                    clicks.add(click);
                }
            }
        }

        currentMonth++;
        if (currentMonth > Calendar.DECEMBER) {
            currentMonth = Calendar.JANUARY;
            currentYear++;
        }
    }

    return clicks;
}

From source file:com.wxxr.nirvana.json.JSONResultTest.java

@SuppressWarnings("unchecked")
public void testCommentWrap() throws Exception {
    JSONResult result = new JSONResult();

    TestAction action = new TestAction();
    stack.push(action);// www . j  a va2s.  c  o m

    // test scape characters
    action.setArray(new String[] { "a", "a", "\"", "\\", "/", "\b", "\f", "\n", "\r", "\t" });

    List list = new ArrayList();

    list.add("b");
    list.add(1);
    list.add(new int[] { 10, 12 });
    action.setCollection(list);

    // beans
    List collection2 = new ArrayList();
    Bean bean1 = new Bean();

    bean1.setStringField("str");
    bean1.setBooleanField(true);
    bean1.setCharField('s');
    bean1.setDoubleField(10.1);
    bean1.setFloatField(1.5f);
    bean1.setIntField(10);
    bean1.setLongField(100);
    bean1.setEnumField(null);
    bean1.setEnumBean(null);

    Bean bean2 = new Bean();

    bean2.setStringField("  ");
    bean2.setBooleanField(false);
    bean2.setFloatField(1.1f);
    bean2.setDoubleField(2.2);
    bean2.setEnumField(AnEnum.ValueC);
    bean2.setEnumBean(AnEnumBean.Three);

    // circular reference
    bean1.setObjectField(bean2);
    bean2.setObjectField(bean1);

    collection2.add(bean1);
    action.setCollection2(collection2);

    // keep order in map
    Map map = new LinkedHashMap();

    map.put("a", 1);
    map.put("c", new float[] { 1.0f, 2.0f });
    action.setMap(map);

    action.setFoo("foo");
    // should be ignored, marked 'transient'
    action.setBar("bar");

    // date
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 1999);
    calendar.set(Calendar.MONTH, Calendar.DECEMBER);
    calendar.set(Calendar.DAY_OF_MONTH, 31);
    calendar.set(Calendar.HOUR_OF_DAY, 11);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    action.setDate(calendar.getTime());
    action.setDate2(calendar.getTime());

    this.invocation.setAction(action);
    result.setWrapWithComments(true);
    result.execute(this.invocation);

    String json = response.getContentAsString();

    String normalizedActual = TestUtils.normalize(json, true);
    String normalizedExpected = TestUtils.normalize(JSONResultTest.class.getResource("json-3.txt"));
    assertEquals(normalizedExpected, normalizedActual);
    assertEquals("application/json;charset=ISO-8859-1", response.getContentType());
}

From source file:com.discovery.darchrow.date.DateUtil.java

/**
 * <span style="color:red">?</span> <code>23:59:59.999</code> <br>
 * //from   w w w  .  ja va  2 s .c  om
 * <pre>
 *   2012-10-11 17:10:30.701,
 * 
 * return 2012-12-31 23:59:59.999
 * </pre>
 * 
 * @param date
 *            ?date
 * @return Date
 * @see #toCalendar(Date)
 * @see Calendar#set(int, int)
 * @see CalendarUtil#resetDayEnd(Calendar)
 * @see Calendar#getTime()
 */
public static Date getLastDateOfThisYear(Date date) {
    Calendar calendar = toCalendar(date);
    calendar.set(Calendar.MONTH, Calendar.DECEMBER);
    calendar.set(Calendar.DAY_OF_MONTH, 31);
    CalendarUtil.resetDayEnd(calendar);
    return CalendarUtil.toDate(calendar);
}

From source file:Time.java

/**
 * Return the 1-based month number of the month of this day. 1 = January, 2 =
 * February and so on.//w w  w  .  ja  va 2  s  .com
 * 
 * @return Month number of this month
 */
public int getMonthNo() {
    // It is tempting to return getMonth() + 1 but this is conceptually
    // wrong, as Calendar month is an enumeration and the values are tags
    // only and can be anything.
    switch (getMonth()) {
    case Calendar.JANUARY:
        return 1;
    case Calendar.FEBRUARY:
        return 2;
    case Calendar.MARCH:
        return 3;
    case Calendar.APRIL:
        return 4;
    case Calendar.MAY:
        return 5;
    case Calendar.JUNE:
        return 6;
    case Calendar.JULY:
        return 7;
    case Calendar.AUGUST:
        return 8;
    case Calendar.SEPTEMBER:
        return 9;
    case Calendar.OCTOBER:
        return 10;
    case Calendar.NOVEMBER:
        return 11;
    case Calendar.DECEMBER:
        return 12;
    }

    // This will never happen
    return 0;
}

From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java

private void initializeListView() {
    setEmptyText(getString(R.string.no_data));

    // add header and footer
    try {/*from   w ww  .  ja va2 s. co  m*/
        setListAdapter(null);
        addListViewHeader();
        mFooterListView = addListViewFooter();
    } catch (Exception e) {
        Timber.e(e, "adding header and footer in income vs expense report");
    }

    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Object positionObj = parent.getItemAtPosition(position);
            Cursor cursor = (Cursor) positionObj;
            if (cursor == null)
                return; // i.e. footer row.
            IncomeVsExpenseReportEntity entity = IncomeVsExpenseReportEntity.from(cursor);
            SearchParameters params = new SearchParameters();

            // show the details for the selected month/year.
            MmxDate dateTime = new MmxDate();
            dateTime.setYear(entity.getYear());
            int month = entity.getMonth();
            if (month != IncomeVsExpensesActivity.SUBTOTAL_MONTH) {
                dateTime.setMonth(entity.getMonth() - 1);
            } else {
                // full year
                dateTime.setMonth(Calendar.JANUARY);
            }
            dateTime.firstDayOfMonth();
            params.dateFrom = dateTime.toDate();

            if (month == IncomeVsExpensesActivity.SUBTOTAL_MONTH) {
                dateTime.setMonth(Calendar.DECEMBER);
            }
            dateTime.lastDayOfMonth();
            params.dateTo = dateTime.toDate();

            Intent intent = IntentFactory.getSearchIntent(getActivity(), params);
            startActivity(intent);
        }
    });
}

From source file:weka.server.JSONProtocol.java

/**
 * Convert a schedule object to a map (ready for encoding to a json string)
 *
 * @param schedule the schedule to convert
 * @return a map//  w w w  .  ja  v a  2s. c o  m
 */
protected static Map<String, Object> scheduleToJsonMap(Schedule schedule) {
    Map<String, Object> scheduleMap = new HashMap<String, Object>();

    scheduleMap.put(SCHEDULE_DATE_FORMAT_KEY, schedule.m_dateFormat);
    SimpleDateFormat sdf = new SimpleDateFormat(schedule.m_dateFormat);
    if (schedule.getStartDate() != null) {
        scheduleMap.put(SCHEDULE_START_DATE_KEY, sdf.format(schedule.getStartDate()));
    }
    if (schedule.getEndDate() != null) {
        scheduleMap.put(SCHEDULE_END_DATE_KEY, sdf.format(schedule.getEndDate()));
    }

    scheduleMap.put(SCHEDULE_REPEAT_UNIT_KEY, schedule.getRepeatUnit());
    scheduleMap.put(SCHEDULE_REPEAT_VALUE_KEY, schedule.getRepeatValue());
    if (schedule.getDayOfTheWeek() != null && schedule.getDayOfTheWeek().size() > 0) {
        String dowList = "";
        for (int dow : schedule.getDayOfTheWeek()) {
            dowList += "," + Schedule.calendarDOWToString(dow);
        }
        dowList = dowList.substring(1);
        scheduleMap.put(SCHEDULE_DAY_OF_WEEK_KEY, dowList);
    }

    if (schedule.getMonthOfTheYear() >= Calendar.JANUARY && schedule.getMonthOfTheYear() <= Calendar.DECEMBER) {
        scheduleMap.put(SCHEDULE_MONTH_OF_YEAR_KEY,
                Schedule.calendarMonthToString(schedule.getMonthOfTheYear()));
    }

    scheduleMap.put(SCHEDULE_DAY_OF_MONTH_KEY, schedule.getDayOfTheMonth());
    if (schedule.getOccurrenceWithinMonth() != null) {
        scheduleMap.put(SCHEDULE_OCCURRENCE_KEY, schedule.getOccurrenceWithinMonth().toString());
    }

    return scheduleMap;
}