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:Main.java

/**
 * Get a list of initial and end calendar of months in the range received
 * @param cStart Calendar date to start//from  www. j av a 2s. co m
 * @param cEnd Calendar date to end
 * @return List<Pair<Calendar, Calendar>> list of calendars (initial and end)
 */
public static List<Pair<Calendar, Calendar>> getRangeInMonths(Calendar cStart, Calendar cEnd) {

    //generate the list
    List<Pair<Calendar, Calendar>> calendars = new ArrayList<>();

    //from the first calendar start adding a month until the actual calendar is after the end
    Calendar cActual = generateCalendar(cStart);
    cActual.set(Calendar.DAY_OF_MONTH, 1);
    Calendar c0;
    Calendar cF;

    while (cActual.compareTo(cEnd) < 0) {

        //calendar start
        if (calendars.size() == 0) {
            c0 = generateCalendar(cStart);
        } else {
            c0 = generateCalendar(cActual);
        }

        //increment a month
        cActual.add(Calendar.MONTH, 1);

        //calendar end
        if (cActual.after(cEnd)) {
            cF = generateCalendar(cEnd);
        } else {
            cF = generateCalendar(cActual);

            //remove 1 day to set the last day of the month
            cF.add(Calendar.DAY_OF_YEAR, -1);
        }

        //add the pair to the list
        calendars.add(new Pair<Calendar, Calendar>(c0, cF));
    }

    //return the list
    return calendars;
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

protected static int computeRequestCount(Context context, ScriptCategory category, String trollId) {

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Calendar instance = Calendar.getInstance();
    instance.add(Calendar.HOUR_OF_DAY, -24);
    Date sinceDate = instance.getTime();

    Cursor cursor = database.rawQuery(SQL_COUNT,
            new String[] { trollId, category.name(), "" + sinceDate.getTime() });
    int result = 0;
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();/*from   w w w .j a v  a2  s . c om*/
        result = cursor.getInt(0);
    }

    cursor.close();
    database.close();

    String format = "Quota for category %s and troll=%s since '%s' is: %d";
    String message = String.format(format, category, trollId, sinceDate, result);
    Log.d(TAG, message);

    return result;
}

From source file:com.sccl.attech.common.utils.DateUtils.java

/**
 * ??//from  w  w  w  .  ja va  2 s .c o  m
 * @param date
 * @return
 */
public static Date getNextDay(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    date = calendar.getTime();
    return date;
}

From source file:com.fengduo.bee.commons.util.DateViewTools.java

public static String yesterdayFull() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    return getFormat(FULL_DATE_FORMAT_PATTERN).format(yesterDate());
}

From source file:com.fengduo.bee.commons.util.DateViewTools.java

public static String nextDay() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
    return getFormat(SIMPLE_DATE_FORMAT_PATTERN).format(calendar.getTime());
}

From source file:com.fengduo.bee.commons.util.DateViewTools.java

public static String nextDayFull() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
    return getFormat(FULL_DATE_FORMAT_PATTERN).format(calendar.getTime());
}

From source file:com.inmobi.messaging.consumer.util.TestUtil.java

static void publishMissingPaths(FileSystem fs, Path baseDir, Date lastCommitTime, Date uptoCommit)
        throws IOException {
    LOG.debug("publishMissingPaths lastCommitTime:" + lastCommitTime + " uptoCommit:" + uptoCommit);
    if (lastCommitTime != null) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(lastCommitTime);//from  w w  w  .j  a  va  2  s .c om
        cal.add(Calendar.MINUTE, 1);
        while (cal.getTime().before(uptoCommit)) {
            Path minDir = DatabusStreamReader.getMinuteDirPath(baseDir, cal.getTime());
            fs.mkdirs(minDir);
            LOG.info("Created minDir:" + minDir);
            cal.add(Calendar.MINUTE, 1);
        }
    } else {
        LOG.info("Nothing to publish");
    }
}

From source file:Main.java

private static Date getNextBus(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//w w  w. j a  va  2s  .co  m

    if (cal.get(Calendar.DAY_OF_WEEK) >= Calendar.MONDAY
            && cal.get(Calendar.DAY_OF_WEEK) <= Calendar.THURSDAY) {
        if (isBefore(cal, mon_thu[mon_thu.length - 1])) {
            setTime(cal, findNext(cal, mon_thu));
        } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
            setTime(cal, fri[0]);
            cal.add(Calendar.DAY_OF_YEAR, 1);
        } else {
            setTime(cal, mon_thu[0]);
            cal.add(Calendar.DAY_OF_YEAR, 1);
        }
    } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {
        if (isBefore(cal, fri[fri.length - 1])) {
            setTime(cal, findNext(cal, fri));
        } else {
            setTime(cal, mon_thu[0]);
            cal.add(Calendar.DAY_OF_YEAR, 3);
        }
    } else {
        setTime(cal, mon_thu[0]);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    }
    return cal.getTime();
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getInternalDownloadFileUrl(int merchantId, long downloadId) throws Exception {

    Configuration conf = PropertiesUtil.getConfiguration();

    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    MerchantStore store = mservice.getMerchantStore(merchantId);

    // ***build fileid***
    StringBuffer urlconstruct = new StringBuffer();
    StringBuffer downloadurl = new StringBuffer();
    Calendar endDate = Calendar.getInstance();
    endDate.add(Calendar.DATE, conf.getInt("core.product.file.downloadmaxdays", 2)); // add 2 days
    Date denddate = endDate.getTime();
    String sedate = DateUtil.formatDate(denddate);

    urlconstruct.append(downloadId).append("|").append(sedate).append("|").append(merchantId);

    String file = EncryptionUtil.encrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant),
            urlconstruct.toString());/*from  w w w .  ja  v a  2 s.  c om*/

    downloadurl.append(ReferenceUtil.buildCheckoutUri(store))
            .append(conf.getString("core.salesmanager.core.downloadFileAction")).append("?fileId=").append(file)
            .append("&mod=productfile");

    return downloadurl.toString();

}

From source file:in.bbat.license.LicenseManager.java

public static JSONObject getLocallyGeneratedLicense(String paramString) {
    Calendar localCalendar = Calendar.getInstance();
    localCalendar.setTime(new Date());
    localCalendar.add(1, 99);
    Date localDate = localCalendar.getTime();
    JSONObject localJSONObject = new JSONObject();
    try {//  ww w .  j a  v a 2  s  .c om
        localJSONObject.put("licenseType", "LittleEye");
        localJSONObject.put("licenseDisplayName", "LittleEye");
        localJSONObject.put("licenseBasis", "TIME_BOUND");
        localJSONObject.put("licenseBasisValue", new SimpleDateFormat(getLogDateFormat()).format(localDate));
        localJSONObject.put("created", new SimpleDateFormat(getLogDateFormat()).format(new Date()));
        localJSONObject.put("bindType", "USER_EMAIL");
        localJSONObject.put("bindAgent", paramString);
        localJSONObject.put("userEmail", paramString);
        localJSONObject.put("numLicenses", 1);
        localJSONObject.put("activationCode", "AAAAA-AAAAA-AAAAA-AAAAA");
        localJSONObject.put("verified", "true");
        localJSONObject.put("version", "1.0");
        localJSONObject.put("checkedOut", "success");
        return localJSONObject;
    } catch (Exception localException) {
        LOG.error("Error constructing a local license object", localException);
    }
    return null;
}