Example usage for java.util Calendar clone

List of usage examples for java.util Calendar clone

Introduction

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

Prototype

@Override
public Object clone() 

Source Link

Document

Creates and returns a copy of this object.

Usage

From source file:Main.java

public static Calendar addMonthToDate(Calendar data, int quantidade) {
    Calendar dataRetorno = (Calendar) data.clone();
    dataRetorno.add(Calendar.MONTH, quantidade);
    return dataRetorno;
}

From source file:Main.java

public static Calendar addDayToDate(Calendar dataInicio, int quantidade) {
    Calendar dataFim = (Calendar) dataInicio.clone();
    dataFim.add(Calendar.DAY_OF_YEAR, quantidade);
    return dataFim;
}

From source file:Main.java

public static int daysBetween(Calendar startDate, Calendar endDate) {

    Calendar date = (Calendar) startDate.clone();
    long daysBetween = 0;
    while (date.before(endDate)) {
        date.add(Calendar.DAY_OF_MONTH, 1);
        daysBetween++;/*w w w  .j ava 2s. c  o  m*/
    }
    return (int) (daysBetween / 365.25);
}

From source file:Main.java

private static Calendar prepareCalendar(int hourOfDay, int minute) {
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();

    calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
    calSet.set(Calendar.MINUTE, minute);
    calSet.set(Calendar.SECOND, 0);
    calSet.set(Calendar.MILLISECOND, 0);

    if (calSet.compareTo(calNow) <= 0) {
        // Today Set time passed, count to tomorrow
        calSet.add(Calendar.DATE, 1);
    }/*from w w w  .  j  ava 2 s. c o m*/
    return calSet;
}

From source file:Main.java

/**
 * Creates a calendar object with the next absolute time determined by hour and minute
 * @param hourOfDay/*from  ww  w.  j av  a  2s .c o  m*/
 * @param minute
 * @return
 */
public static Calendar getNextAlarmTimeAbsolute(int hourOfDay, int minute) {
    Calendar cal = Calendar.getInstance();
    Calendar calNow = (Calendar) cal.clone();

    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    if (cal.compareTo(calNow) <= 0) {
        //Today's time passed, count to tomorrow
        cal.add(Calendar.DATE, 1);
    }
    return cal;
}

From source file:MainGeneratePicasaIniFile.java

public static long daysBetween(Calendar startDate, Calendar endDate) {
    Calendar date = (Calendar) startDate.clone();
    long daysBetween = 0;
    while (date.before(endDate)) {
        date.add(Calendar.DAY_OF_MONTH, 1);
        daysBetween++;/*  w w w. j  a  v  a  2  s  .  c  om*/
    }
    return daysBetween;
}

From source file:br.com.gerenciapessoal.repository.Lancamentos.java

private static Map<Date, BigDecimal> criarMapaVazio(Integer numeroDeDias, Calendar dataInicial) {

    dataInicial = (Calendar) dataInicial.clone();

    Map<Date, BigDecimal> mapaInicial = new TreeMap<>();

    for (int i = 0; i < numeroDeDias; i++) {
        mapaInicial.put(dataInicial.getTime(), BigDecimal.ZERO);
        dataInicial.add(Calendar.DAY_OF_MONTH, 1);
    }//from w  w  w. j a v a  2  s . co  m

    return mapaInicial;
}

From source file:org.openhab.binding.astro.internal.util.DateTimeUtils.java

/**
 * Returns the end of day julian date from the calendar object.
 *///from w ww .ja va  2s. com
public static double endOfDayDateToJulianDate(Calendar calendar) {
    Calendar cal = (Calendar) calendar.clone();
    cal = DateUtils.ceiling(cal, Calendar.DATE);
    cal.add(Calendar.MILLISECOND, -1);
    return dateToJulianDate(cal);
}

From source file:uk.ac.ox.oucs.vle.SampleDataLoader.java

public static Date addWeeks(Calendar cal, int i) {
    Calendar opens = (Calendar) cal.clone();
    opens.add(Calendar.WEEK_OF_YEAR, i);
    return opens.getTime();
}

From source file:fr.openwide.core.commons.util.CloneUtils.java

/**
 * Clne un calendar.// w w w.  jav  a 2 s . c o m
 * Cette mthode est null safe.
 * 
 * @param calendar  clner
 * @return clne du calendar pass en paramtre
 */
public static Calendar clone(Calendar calendar) {
    if (calendar == null) {
        return null;
    } else {
        return (Calendar) calendar.clone();
    }
}