Example usage for java.util Calendar getActualMinimum

List of usage examples for java.util Calendar getActualMinimum

Introduction

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

Prototype

public int getActualMinimum(int field) 

Source Link

Document

Returns the minimum value that the specified calendar field could have, given the time value of this Calendar.

Usage

From source file:de.tor.tribes.ui.components.DatePicker.java

public void buildCalendar() {
    jLabelMonth.setText(monthAndYear.format(selectedDate));

    Calendar temp = new GregorianCalendar();
    temp.setTime(selectedDate);/*from   w  w  w  . j  a  va  2 s  .  co  m*/
    int maxDaysInMonth = temp.getActualMaximum(Calendar.DAY_OF_MONTH);
    int firstdayInMonth = temp.getActualMinimum(Calendar.DAY_OF_MONTH);

    temp.set(Calendar.DAY_OF_MONTH, firstdayInMonth);
    int dayOfWeek = mapDayOfWeek(temp.get(Calendar.DAY_OF_WEEK));

    int currentField = 0;
    //ensure that at least one day of prev month is shown
    int preDaysToAdd = ((dayOfWeek + 5) % 7) + 1;

    temp.add(Calendar.MONTH, -1);
    temp.set(Calendar.DAY_OF_MONTH, temp.getActualMaximum(Calendar.DAY_OF_MONTH) - preDaysToAdd + 1);
    for (; currentField < preDaysToAdd; currentField++) {
        //days belong to last month
        CrossedLabel current = daysInMonth[currentField / 7][currentField % 7];
        current.setText("" + temp.get(Calendar.DAY_OF_MONTH));
        current.setForeground(LIGHT_GRAY);
        datesInMonth[currentField / 7][currentField % 7] = temp.getTime();

        temp.add(Calendar.DAY_OF_MONTH, 1);
    }

    //normal days of month
    for (int i = firstdayInMonth; i <= maxDaysInMonth; i++, currentField++) {
        CrossedLabel current = daysInMonth[currentField / 7][currentField % 7];
        current.setText("" + temp.get(Calendar.DAY_OF_MONTH));
        current.setForeground(BLACK);
        datesInMonth[currentField / 7][currentField % 7] = temp.getTime();

        temp.add(Calendar.DAY_OF_MONTH, 1);
    }

    //post days of month
    for (; currentField < WEEKS_TO_SHOW * 7; currentField++) {
        CrossedLabel current = daysInMonth[currentField / 7][currentField % 7];
        current.setText("" + temp.get(Calendar.DAY_OF_MONTH));
        current.setForeground(LIGHT_GRAY);
        datesInMonth[currentField / 7][currentField % 7] = temp.getTime();

        temp.add(Calendar.DAY_OF_MONTH, 1);
    }

    for (int i = 0; i < WEEKS_TO_SHOW * 7; i++) {
        if (selectedDate.equals(datesInMonth[i / 7][i % 7])) {
            daysInMonth[i / 7][i % 7].cross();
        } else {
            daysInMonth[i / 7][i % 7].uncross();
        }
    }

}

From source file:br.ufg.calendario.components.HomeBean.java

public void setMesListener(ActionEvent event) throws ParseException {
    try {// w  ww  . j a  v  a 2s.  c  o  m
        int mes = Integer.parseInt((String) event.getComponent().getAttributes().get("mes"));
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, calendario.getAno());
        calendar.set(Calendar.MONTH, mes - 1);
        int diaInicio = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
        int diaTermino = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-M-d");
        Date dataInicio = dateFormatter
                .parse(String.format("%04d-%02d-%02d", calendario.getAno(), mes, diaInicio));
        Date dataTermino = dateFormatter
                .parse(String.format("%04d-%02d-%02d", calendario.getAno(), mes, diaTermino));
        setBuscaDataInicio(dataInicio);
        setBuscaDataTermino(dataTermino);
        System.out.format("%02d/%02d/%04d - %02d/%02d/%04d\n", diaInicio, mes, calendario.getAno(), diaTermino,
                mes, calendario.getAno());
        System.out.format("periodo: %s a %s\n", dateFormatter.format(dataInicio),
                dateFormatter.format(dataTermino));
    } catch (Exception e) {
        System.out.println("error: " + e.getMessage());
    }

}

From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java

/**
 * return a timestamp Object which correspond at the fist minute of the date
 * .//from  w  w w  . j a  v  a  2s  . co  m
 * @param date the date
 * @return a timestamp Object which correspond at the fist minute of the
 *         date .
 */
public static Timestamp getFirstMinute(Timestamp date) {
    Calendar caldate = new GregorianCalendar();
    caldate.setTime(date);
    caldate.set(Calendar.MILLISECOND, caldate.getActualMinimum(Calendar.MILLISECOND));
    caldate.set(Calendar.SECOND, caldate.getActualMinimum(Calendar.SECOND));
    caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMinimum(Calendar.HOUR_OF_DAY));
    caldate.set(Calendar.MINUTE, caldate.getActualMinimum(Calendar.MINUTE));

    Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis());

    return timeStamp;
}

From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java

/**
 * return the first day of week function of the date .
 * @param date the date/*  ww  w  .j  a  v a  2s  .  c o  m*/
 * @return the first day of week function of the date.
 */
public static Timestamp getFirstDayOfWeek(Timestamp date) {
    Calendar caldate = new GregorianCalendar();
    caldate.setTime(date);
    caldate.set(Calendar.MILLISECOND, caldate.getActualMinimum(Calendar.MILLISECOND));
    caldate.set(Calendar.SECOND, caldate.getActualMinimum(Calendar.SECOND));
    caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMinimum(Calendar.HOUR_OF_DAY));
    caldate.set(Calendar.MINUTE, caldate.getActualMinimum(Calendar.MINUTE));
    caldate.set(Calendar.DAY_OF_WEEK, caldate.getFirstDayOfWeek());

    Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis());

    return timeStamp;
}

From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java

/**
 * return the first day of month function of the date .
 * @param date the date/* w  w  w.j  a  v  a 2s .  com*/
 * @return the first day of mont function of the date.
 */
public static Timestamp getFirstDayOfMonth(Timestamp date) {
    Calendar caldate = new GregorianCalendar();
    caldate.setTime(date);
    caldate.set(Calendar.MILLISECOND, caldate.getActualMinimum(Calendar.MILLISECOND));
    caldate.set(Calendar.SECOND, caldate.getActualMinimum(Calendar.SECOND));
    caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMinimum(Calendar.HOUR_OF_DAY));
    caldate.set(Calendar.MINUTE, caldate.getActualMinimum(Calendar.MINUTE));
    caldate.set(Calendar.DAY_OF_MONTH, caldate.getActualMinimum(Calendar.DAY_OF_MONTH));

    Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis());

    return timeStamp;
}

From source file:DateUtil.java

/**
 * Returns true if the two calendars represent dates that fall in the same
 * week, else false. A week here is defined by the Calendar.WEEK_OF_YEAR
 * package. Special provisions have been made to test weeks than may span the
 * end/beginning of a year, and returning true if the two calendars are
 * specifying dates within such a week, despite Calendar.WEEK_OF_YEAR being
 * unequal for the two Calendars.//from www . j av a  2  s .c  om
 * 
 * @param c1
 *          Calendar one.
 * @param c2
 *          Calendar two.
 * @return boolean.
 */
public static boolean inSameWeek(Calendar c1, Calendar c2) {
    if (inSameYear(c1, c2) && (c1.get(Calendar.WEEK_OF_YEAR) == c2.get(Calendar.WEEK_OF_YEAR)))
        return true;

    Calendar tmp;
    if (c1.before(c2)) {
        tmp = c2;
        c2 = c1;
        c1 = tmp;
    }

    int c1week = c1.get(Calendar.WEEK_OF_YEAR);
    int c2week = c1.get(Calendar.WEEK_OF_YEAR);

    if (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) + 1) {
        if (c1week == c1.getActualMinimum(Calendar.WEEK_OF_YEAR)
                && c2week == c2.getActualMaximum(Calendar.WEEK_OF_YEAR)) {
            tmp = (Calendar) c2.clone();
            tmp.add(Calendar.DAY_OF_YEAR, 7);
            if (tmp.get(Calendar.WEEK_OF_YEAR) > c1week)
                return true;
        }
    }

    return false;
}

From source file:com.rogchen.common.xml.UtilDateTime.java

public static Date getEarliestDate() {
    Calendar cal = getCalendarInstance(TimeZone.getTimeZone("GMT"), Locale.getDefault());
    cal.set(Calendar.YEAR, cal.getActualMinimum(Calendar.YEAR));
    cal.set(Calendar.MONTH, cal.getActualMinimum(Calendar.MONTH));
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);//from   w ww . j a  v  a 2s .  com
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java

/**
 * return a timestamp Object which correspond with the string specified in
 * parameter./* www  . jav a  2  s.co  m*/
 * @param strDate the date who must convert
 * @param locale the locale
 * @return a timestamp Object which correspond with the string specified in
 *         parameter.
 */
public static Timestamp getFirstMinute(String strDate, Locale locale) {
    try {
        Date date;
        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        dateFormat.setLenient(false);
        date = dateFormat.parse(strDate.trim());

        Calendar caldate = new GregorianCalendar();
        caldate.setTime(date);
        caldate.set(Calendar.MILLISECOND, 0);
        caldate.set(Calendar.SECOND, 0);
        caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMinimum(Calendar.HOUR_OF_DAY));
        caldate.set(Calendar.MINUTE, caldate.getActualMinimum(Calendar.MINUTE));

        Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis());

        return timeStamp;
    } catch (ParseException e) {
        return null;
    }
}

From source file:picocash.Picocash.java

private List<Transaction> getTransactionsForSelectedMonth(Account account, int year, int month) {
    log.debug("selected [" + account + "] on [" + year + "/" + month + "]");
    Calendar date = Calendar.getInstance();
    date.setLenient(false);//  w w  w.ja  va2  s . co m
    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, date.getActualMinimum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND));
    long startDate = date.getTimeInMillis();
    if (log.isTraceEnabled()) {
        log.trace("startDate [" + date.getTime() + "]");
    }
    date.set(Calendar.DAY_OF_MONTH, date.getActualMaximum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    long endDate = date.getTimeInMillis();
    if (log.isTraceEnabled()) {
        log.trace("endDate [" + date.getTime() + "]");
    }
    final List<Transaction> transactions = Services.getSelectedPersistenceMan()
            .getAllTransactionsForAccount(account, startDate, endDate);
    if (log.isTraceEnabled()) {
        final List<Transaction> allTransactionsForAccount = Services.getSelectedPersistenceMan()
                .getAllTransactionsForAccount(account);
        for (Transaction transaction : allTransactionsForAccount) {
            final long transactionDate = transaction.getTransactionDate();
            Calendar test = Calendar.getInstance();
            test.setTimeInMillis(transactionDate);
            log.trace(test.getTime());
        }
        log.trace("current available transactions [" + transactions.size() + "]");
    }
    return transactions;
}

From source file:com.mss.msp.util.DateUtility.java

public String FirstDateOfCurrentMonth() throws ParseException {
    Calendar cal = Calendar.getInstance();
    int cur_year = cal.get(Calendar.YEAR);
    int cur_month = cal.get(Calendar.MONTH);

    cal.set(cur_year, cur_month, 1);// ww  w.j  ava  2  s .com

    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));

    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

    String lastDate = sdf.format(cal.getTime());
    return lastDate;

}