Example usage for org.apache.commons.lang3.time DateUtils getFragmentInDays

List of usage examples for org.apache.commons.lang3.time DateUtils getFragmentInDays

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils getFragmentInDays.

Prototype

public static long getFragmentInDays(final Calendar calendar, final int fragment) 

Source Link

Document

Returns the number of days within the fragment.

Usage

From source file:com.googlecode.commons.swing.component.datetime.MiniDateCalendar.java

public void refresh() {
    final Date value = getValue();
    final Date startOfMonth = DateUtils2.getStartOfMonth(value);
    final Date endOfMonth = DateUtils2.getEndOfMonth(value);
    final long daysOfMonth = DateUtils.getFragmentInDays(endOfMonth, Calendar.MONTH);

    final NumberFormat nfDay = new DecimalFormat("00");
    final SimpleDateFormat formatMonth = new SimpleDateFormat("MM.yyyy");
    lblMonth.setText(formatMonth.format(getValue()));

    for (DayButton btn : days) {
        btn.setText("");
        btn.setEnabled(false);/*from w w  w .j  a  va  2s. c  o m*/
        btn.setValue(null);
        btn.setSelected(false);
    }

    int startWeekday = DateUtils2.getWeekNumber(startOfMonth);
    for (int i = 0; i < daysOfMonth; i++) {
        DayButton btn = days.get(i + orderedWeekdays.indexOf(startWeekday));
        btn.setText(nfDay.format(i + 1));
        btn.value = DateUtils.setDays(startOfMonth, i + 1);
        btn.setEnabled(true);
        if (DateUtils.isSameDay(btn.value, this.value)) {
            btn.setSelected(true);
        }
    }

}