Example usage for java.util GregorianCalendar add

List of usage examples for java.util GregorianCalendar add

Introduction

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

Prototype

@Override
public void add(int field, int amount) 

Source Link

Document

Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:org.opencms.ui.login.CmsLoginHelper.java

/**
 * Sets the cookie in the response.<p>
 *
 * @param cookie the cookie to set//from   ww w . j  av a2 s. c o  m
 * @param delete flag to determine if the cookir should be deleted
 * @param request the current request
 * @param response the current response
 */
protected static void setCookie(Cookie cookie, boolean delete, HttpServletRequest request,
        HttpServletResponse response) {

    if (request.getAttribute(PARAM_PREDEF_OUFQN) != null) {
        // prevent the use of cookies if using a direct ou login url
        return;
    }
    int maxAge = 0;
    if (!delete) {
        // set the expiration date of the cookie to six months from today
        GregorianCalendar cal = new GregorianCalendar();
        cal.add(Calendar.MONTH, 6);
        maxAge = (int) ((cal.getTimeInMillis() - System.currentTimeMillis()) / 1000);
    }
    cookie.setMaxAge(maxAge);
    // set the path
    cookie.setPath(CmsStringUtil.joinPaths(OpenCms.getStaticExportManager().getVfsPrefix(),
            CmsWorkplaceLoginHandler.LOGIN_HANDLER));
    // set the cookie
    response.addCookie(cookie);
}

From source file:org.nuclos.common2.SeriesUtils.java

/**
 * /*from w  w  w  .  j av a2  s  .c om*/
 * @param dateFrom
 * @param dateUntil
 * @return
 */
public static List<DateTime> getPossibleDates(String series, DateTime dateFrom, DateTime dateUntil) {
    List<DateTime> result = new ArrayList<DateTime>();

    if (dateUntil.before(dateFrom)) {
        return result;
    }

    final GregorianCalendar calendar = new GregorianCalendar();

    DateTime dateCalculated = getSeriesNext(series, dateFrom);
    while (dateCalculated.before(dateUntil)) {
        result.add(dateCalculated);

        calendar.setTime(dateCalculated.getDate());
        calendar.add(GregorianCalendar.MINUTE, 1);
        dateCalculated = getSeriesNext(series, new DateTime(calendar.getTime()));
    }

    return result;
}

From source file:com.emcopentechnologies.viprcloudstorage.WAStorageClient.java

/**
 * Generates SAS URL for blob in Cloud storage account
 * @param storageAccountName//  ww  w.  j av  a  2  s.  com
 * @param storageAccountKey
 * @param containerName
 * @param strBlobURL
 * @return SAS URL
 * @throws Exception
 */
public static String generateSASURL(String storageAccountName, String storageAccountKey, String containerName,
        String saBlobEndPoint) throws Exception {
    StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(storageAccountName,
            storageAccountKey);
    URL blobURL = new URL(saBlobEndPoint);
    String saBlobURI = new StringBuilder().append(blobURL.getProtocol()).append("://")
            .append(storageAccountName).append(".").append(blobURL.getHost()).append("/").toString();
    CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(credentials, new URI(saBlobURI),
            new URI(getCustomURI(storageAccountName, QUEUE, saBlobURI)),
            new URI(getCustomURI(storageAccountName, TABLE, saBlobURI)));
    // Create the blob client.
    CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference(containerName);

    // At this point need to throw an error back since container itself did not exist.
    if (!container.exists()) {
        throw new Exception("WAStorageClient: generateSASURL: Container " + containerName
                + " does not exist in storage account " + storageAccountName);
    }

    SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.setTime(new Date());

    //policy.setSharedAccessStartTime(calendar.getTime());
    calendar.add(Calendar.HOUR, 1);
    policy.setSharedAccessExpiryTime(calendar.getTime());
    policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ));

    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
    containerPermissions.getSharedAccessPolicies().put("jenkins" + System.currentTimeMillis(), policy);
    container.uploadPermissions(containerPermissions);

    // Create a shared access signature for the container.
    String sas = container.generateSharedAccessSignature(policy, null);

    return sas;
}

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * Ajoute un certain nombre de jour  une date
 * //  w  ww.  j  a va2s .  co m
 * @param date1 Date sous forme de jave.util.Date
 * @param nbdays nombre de jours  ajouter
 * @return la date avec le nombre de jour ajout
 */
public static java.util.Date addDaysDate(final java.util.Date date1, final int nbdays) {
    if (date1 == null) {
        return null;
    }

    final GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date1);
    cal.add(Calendar.DATE, nbdays);

    return cal.getTime();
}

From source file:com.microsoftopentechnologies.windowsazurestorage.WAStorageClient.java

public static SharedAccessBlobPolicy generatePolicy() {
    SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.setTime(new Date());

    calendar.add(Calendar.HOUR, 1);
    policy.setSharedAccessExpiryTime(calendar.getTime());
    policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ));

    return policy;
}

From source file:org.apache.ranger.audit.provider.MiscUtil.java

public static Date getUTCDateForLocalDate(Date date) {
    TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
    Calendar local = Calendar.getInstance();
    int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
    GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
    utc.setTimeInMillis(date.getTime());
    utc.add(Calendar.MILLISECOND, -offset);
    return utc.getTime();
}

From source file:org.apache.ranger.audit.provider.MiscUtil.java

public static Date getUTCDate() {
    TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
    Calendar local = Calendar.getInstance();
    int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
    GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
    utc.setTimeInMillis(local.getTimeInMillis());
    utc.add(Calendar.MILLISECOND, -offset);
    return utc.getTime();
}

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * retourne le porchain jour de la semaine saisi en paramtre par rapport  la date d'entre
 * /*from  ww  w . ja  va2  s  .co m*/
 * @param date date d'entre
 * @param dayofweek Jour de la semaine  utiliser
 * @return la date du prochain jour de la semaine
 */
public static java.util.Date getNext(final java.util.Date date, final int dayofweek) {
    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);

    final int actualday = gc.get(Calendar.DAY_OF_WEEK);
    gc.add(Calendar.DATE, ((dayofweek - actualday + WEEK_DAYS) % WEEK_DAYS));

    return gc.getTime();
}

From source file:com.sammyun.util.DateUtil.java

/**
 * ?datas,datas?0??datasdatas0??datas// ww  w.j  av a2s . com
 * 
 * @param ?
 * @return 
 */
public static Date getDate(int datas) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(GregorianCalendar.DATE, datas);
    String begin = new java.sql.Date(calendar.getTime().getTime()).toString();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date beginDate = null;
    try {
        beginDate = sdf.parse(begin);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return beginDate;
}

From source file:com.sammyun.util.DateUtil.java

/**
 * ??//from  ww w .j  a  va  2  s.c o m
 * 
 * @param inDate 
 * @param days ?
 * @return Date
 */
public static Date getDateByAddDays(Date inDate, int days) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(inDate);
    calendar.add(Calendar.DATE, days);
    return calendar.getTime();
}