Example usage for java.util Calendar add

List of usage examples for java.util Calendar add

Introduction

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

Prototype

public abstract void add(int field, int amount);

Source Link

Document

Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:com.linuxbox.enkive.teststats.StatsDayGrainTest.java

@BeforeClass
public static void setUp() throws ParseException, GathererException {
    coll = TestHelper.GetTestCollection();
    client = TestHelper.BuildClient();/*from  ww w  .ja v  a  2 s. c o m*/
    grain = new DayConsolidator(client);

    List<Map<String, Object>> stats = (new HourConsolidator(client)).consolidateData();
    Map<String, Object> timeMap = new HashMap<String, Object>();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, 1);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.HOUR, 0);
    for (int i = 0; i < 10; i++) {
        if (i == 5) {
            cal.add(Calendar.DATE, -1);
        }
        timeMap.put(CONSOLIDATION_MAX, cal.getTime());
        timeMap.put(CONSOLIDATION_MIN, cal.getTime());
        for (Map<String, Object> data : stats) {
            data.put(STAT_TIMESTAMP, timeMap);
        }
        client.storeData(stats);
    }
    dataCount = coll.count();
}

From source file:com.linuxbox.enkive.teststats.StatsWeekGrainTest.java

@BeforeClass
public static void setUp() throws ParseException, GathererException {
    coll = TestHelper.GetTestCollection();
    client = TestHelper.BuildClient();/*from  w w  w .  jav  a  2 s. com*/
    grain = new WeekConsolidator(client);

    List<Map<String, Object>> stats = (new DayConsolidator(client)).consolidateData();
    Map<String, Object> timeMap = createMap();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.HOUR, 0);
    for (int i = 0; i < 10; i++) {
        if (i == 5) {
            cal.add(Calendar.WEEK_OF_MONTH, -1);
        }
        timeMap.put(CONSOLIDATION_MAX, cal.getTime());
        timeMap.put(CONSOLIDATION_MIN, cal.getTime());
        for (Map<String, Object> data : stats) {
            data.put(STAT_TIMESTAMP, timeMap);
        }
        client.storeData(stats);
    }
    dataCount = coll.count();
}

From source file:net.firejack.platform.core.utils.DateUtils.java

/**
 * Increments the date to round it on week level
 * @param date - date to be incremented/*from  w  w w.  j  a v a  2  s  .  c  om*/
 * @return incremented date
 */
public static Date ceilDateToWeek(Date date) {
    date = addWeeks(date, 1);
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
        cal.add(Calendar.DAY_OF_MONTH, -1);
    }
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return addMinutes(cal.getTime(), -1);
}

From source file:com.example.mediastock.util.Utilities.java

/**
 * Method to get the date./*w w w.j  a  v  a2s .  c o  m*/
 *
 * @param day the day of a certain day
 * @return a date string
 */
public static String getDate(int day) {
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -day);

    Date d = calendar.getTime();

    return ft.format(d);
}

From source file:com.sam_chordas.android.stockhawk.data.FetchDetailStockTask.java

public static String get30daysTimeStamp() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
    Date now = new Date();
    String sToday = sdfDate.format(now);
    Calendar c = Calendar.getInstance();
    try {//w  ww.ja va  2s . c  om
        c.setTime(sdfDate.parse(sToday));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    c.add(Calendar.DATE, -35); // number of days to add, can also use Calendar.DAY_OF_MONTH in place of Calendar.DATE

    String output = sdfDate.format(c.getTime());

    return output;
}

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   www. j  a va 2  s.  c om*/

    return mapaInicial;
}

From source file:com.ourlife.dev.common.utils.DateUtils.java

/**
 * ??/*w  w  w. jav  a 2 s .c o m*/
 * 
 * @param date
 * @return
 */
public static String[] getMonthBeginTimeAndEndTime(String date) {
    String[] dates = new String[2];
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(DateUtils.parseDate(date));
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
    dates[0] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");

    calendar.add(Calendar.MONTH, 1);
    dates[1] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");

    return dates;
}

From source file:com.scf.core.EnvTest.java

public static List<Date> getSelectableDateTimeList() {
    String deliveryCycle = "7";

    if (StringUtils.isEmpty(deliveryCycle)) {
        throw new AppException(ExCode.SYS_002);
    }/*from ww  w .  jav  a 2s . c  o m*/

    Date curDate = DatetimeUtilies.currentDay();

    List<Date> selectableDateList = new ArrayList<Date>(Integer.valueOf(deliveryCycle));
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.setTime(curDate);

    int i = 0;
    String[] d = { "07", "16" };
    while (i < Integer.valueOf(deliveryCycle)) {
        tomorrow.add(Calendar.DATE, 1);
        for (String deliveryHour : d) {
            Calendar tomorrowDetail = Calendar.getInstance();
            tomorrowDetail.setTime(tomorrow.getTime());
            tomorrowDetail.set(Calendar.HOUR_OF_DAY, Integer.parseInt(deliveryHour));
            selectableDateList.add(tomorrowDetail.getTime());
        }
        i++;
    }

    return selectableDateList;
}

From source file:helper.util.DateHelper.java

public static CalendarRange getRangeHoursBeforeNow(TimeZone tz, int hours) {
    Calendar start = Calendar.getInstance(tz);
    Calendar end = Calendar.getInstance(tz);
    start.setTimeInMillis(end.getTimeInMillis());
    start.add(Calendar.HOUR_OF_DAY, -hours);
    //fix for BST range issue on check (first dock issue). 
    // BST is not observed so jst roll forward here)
    // also allows for normal variations in timestamp (will still include last one if +n minutes)
    end.add(Calendar.HOUR_OF_DAY, 24);
    return new CalendarRange(start, end);
}

From source file:com.aurel.track.fieldType.bulkSetters.DateBulkSetter.java

/**
 * Shift a date by a number of days /*from ww w .  j a v  a 2 s . c o  m*/
 * @param originalDate
 * @param daysOffset
 * @return
 */
protected static Date shiftByDays(Date originalDate, Integer daysOffset) {
    if (daysOffset != null && daysOffset.intValue() != 0) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(originalDate);
        calendar.add(Calendar.DATE, daysOffset.intValue());
        while (WorkDaysConfigImplementation.isNonWorkingDay(calendar.getTime(), null)) {
            calendar.add(Calendar.DATE, 1);
        }
        return calendar.getTime();
    }
    return originalDate;
}