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.salesmanager.core.util.FileUtil.java

public static String getAdminPasswordResetUrl(MerchantUserInformation information, MerchantStore store)
        throws Exception {

    Configuration conf = PropertiesUtil.getConfiguration();

    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);

    // order id and, expiration date and language
    urlconstruct.append(information.getMerchantUserId()).append("|").append(sedate);

    String lang = conf.getString("core.system.defaultlanguage", "en");
    if (information != null) {
        lang = information.getUserlang();
    }//from  www  .  ja va 2 s.c om

    String file = EncryptionUtil.encrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant),
            urlconstruct.toString());

    downloadurl.append(ReferenceUtil.buildCentralUri(store))
            .append("/anonymous" + conf.getString("core.salesmanager.core.resetPasswordAction"))
            .append("?urlId=").append(file).append("&lang=").append(lang);

    return downloadurl.toString();

}

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

public static String getOrderDownloadFileUrl(Order order, Customer customer) throws Exception {

    Configuration conf = PropertiesUtil.getConfiguration();

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

    // ***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);

    // order id and, expiration date and language
    urlconstruct.append(order.getOrderId()).append("|").append("|").append(sedate);

    String lang = conf.getString("core.system.defaultlanguage", "en");
    if (customer != null) {
        lang = customer.getCustomerLang();
    }/*  ww  w  . ja v  a2  s  .co m*/

    String file = EncryptionUtil.encrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant),
            urlconstruct.toString());

    downloadurl.append(ReferenceUtil.buildCheckoutUri(store))
            .append(conf.getString("core.salesmanager.core.viewFilesAction")).append("?fileId=").append(file)
            .append("&lang=").append(lang);

    return downloadurl.toString();

}

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

public static List<MhSpRequest> listLatestRequestsSince(Context context, String trollId, int dayCount) {
    List<MhSpRequest> result = new ArrayList<MhSpRequest>();

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

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

    Calendar calendar = Calendar.getInstance();

    Cursor cursor = database.rawQuery(SQL_LIST_REQUESTS_SINCE,
            new String[] { trollId, "" + sinceDate.getTime() });
    while (cursor.moveToNext()) {
        long startTimeMillis = cursor.getLong(0);
        long endTimeMillis = cursor.getLong(1);
        String scriptName = cursor.getString(2);
        String status = cursor.getString(3);

        calendar.setTimeInMillis(startTimeMillis);
        Date date = calendar.getTime();
        PublicScript script = PublicScript.valueOf(scriptName);

        long duration = 0;
        if (endTimeMillis > 0) {
            duration = endTimeMillis - startTimeMillis;
        }//from w  w w .j  a  va 2  s  .  c o m
        MhSpRequest request = new MhSpRequest(date, duration, script, status);
        result.add(request);
    }

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

    return result;
}

From source file:com.greenline.guahao.biz.util.DateUtils.java

/**
 * ???0?7?/*from   w w  w.j av a2 s  .c o  m*/
 * 
 * @param date
 * @return int
 */
public static int getIndexInCycle(String date) {
    try {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, 1); // 
        int d = cal.get(Calendar.DAY_OF_WEEK); // 
        cal.setTime(df.parse(date));
        int id = cal.get(Calendar.DAY_OF_WEEK); // 
        int idx = id - d;
        idx = idx < 0 ? idx + 7 : idx; // 7
        return idx;
    } catch (Exception e) {
        logger.error("???", e);
    }
    return -1;
}

From source file:freebase.api.FreebaseAPI2.java

public static void FetchingFromGoogleAPI() {

    int max_step = 1;
    int step = 0;

    int month_step = 1;
    Calendar last_date = Calendar.getInstance();
    last_date.set(Calendar.YEAR, 2016);
    last_date.set(Calendar.MONTH, 0);
    last_date.set(Calendar.DAY_OF_MONTH, 1);

    Calendar from_date = Calendar.getInstance();
    from_date.set(Calendar.YEAR, 2000);
    from_date.set(Calendar.MONTH, 0);
    from_date.set(Calendar.DAY_OF_MONTH, 1);

    Calendar to_date = (Calendar) from_date.clone();
    to_date.add(Calendar.MONTH, month_step);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    while (true) {
        //            if (step > max_step) {
        //                break;
        //            }
        //            System.out.println(">>> Cursor = " + current_cursor);
        //            if (/*films == null || films.isEmpty() ||*/step == max_step) {
        //                System.out.println("Films is null or zero size. Break.");
        //                break;
        //            }
        if (from_date.after(last_date)) {
            System.out.println("Date is after last date");
            break;
        }/*from www  . j a v  a 2 s.c om*/
        String fromDate = sdf.format(from_date.getTime());
        String toDate = sdf.format(to_date.getTime());
        System.out.println(step + " ) fetch films from " + fromDate + " to " + toDate);
        step++;
        List<Film> films = getFilms(fromDate, toDate);
        System.out.println("Films#: " + films.size());
        writeToFiles(films);
        //            for (Film f : films) {
        //                System.out.println(f);
        //            }
        from_date.add(Calendar.MONTH, month_step);
        to_date.add(Calendar.MONTH, month_step);

    }
}

From source file:com.baifendian.swordfish.execserver.parameter.placeholder.TimePlaceholderUtil.java

/**
 * ??? <p>/*from w  w  w.  j  av  a2 s.  co  m*/
 */
public static Date getLastDayOfMonth(Date date) {
    Calendar cal = Calendar.getInstance();

    cal.setTime(date);

    // ? 1 ??
    cal.add(Calendar.MONTH, 1);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.add(Calendar.DAY_OF_MONTH, -1);

    return cal.getTime();
}

From source file:Main.java

private static String getDayOfWeek(String format, int calendarField) {
    String strDate = null;/*ww w . j  a v a  2  s.c  o m*/
    try {
        Calendar c = new GregorianCalendar();
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (week == calendarField) {
            strDate = mSimpleDateFormat.format(c.getTime());
        } else {
            int offectDay = calendarField - week;
            if (calendarField == Calendar.SUNDAY) {
                offectDay = 7 - Math.abs(offectDay);
            }
            c.add(Calendar.DATE, offectDay);
            strDate = mSimpleDateFormat.format(c.getTime());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return strDate;
}

From source file:org.callistasoftware.netcare.web.util.WebUtil.java

/**
 * Creates test data for app.store tests (app. approval process).
 * //from w w  w  .  j a  v  a 2s  . c  om
 * @param sc
 *            the servlet context.
 */
public static final void setupIosTestData(final ServletContext sc) {
    final WebApplicationContext wc = getWebRequest(sc);

    final String careActorHsa = "app-test-giver";

    final TestDataHelper td = new TestDataHelper(sc);

    final PatientRepository bean = wc.getBean(PatientRepository.class);
    final CareActorRepository careActorRepo = wc.getBean(CareActorRepository.class);
    final CareUnitRepository cuRepo = wc.getBean(CareUnitRepository.class);
    final ActivityCategoryRepository catRepo = wc.getBean(ActivityCategoryRepository.class);
    final ActivityTypeRepository atRepo = wc.getBean(ActivityTypeRepository.class);
    final ActivityDefinitionRepository adRepo = wc.getBean(ActivityDefinitionRepository.class);
    final HealthPlanRepository hpRepo = wc.getBean(HealthPlanRepository.class);
    final HealthPlanService hps = wc.getBean(HealthPlanService.class);
    final CountyCouncilRepository ccRepo = wc.getBean(CountyCouncilRepository.class);
    final RoleRepository roleRepo = wc.getBean(RoleRepository.class);

    if (careActorRepo.findByHsaId(careActorHsa) != null) {
        log.info("Test data already setup. Aborting...");
        return;
    }

    final RoleEntity careActorRole = td.newCareActorRole();
    final CountyCouncilEntity jkpg = td.newCountyCouncil(CountyCouncil.JONKOPING);
    final MeasureUnitEntity mue = td.newMeasureUnit("m", "Meter");

    final ActivityCategoryEntity cat = catRepo.save(ActivityCategoryEntity.newEntity("Fysisk aktivitet"));
    final CareUnitEntity cu = CareUnitEntity.newEntity("ap-test-unit", jkpg);
    cu.setName("Jnkpings vrdcentral");
    cuRepo.save(cu);
    cuRepo.flush();

    ActivityTypeEntity ate = ActivityTypeEntity.newEntity("Lpning", cat, cu, AccessLevel.CAREUNIT);
    MeasurementTypeEntity.newEntity(ate, "Distans", MeasurementValueType.SINGLE_VALUE, mue, false, 0);
    EstimationTypeEntity.newEntity(ate, "Knsla", "Ltt", "Tufft", 0, 10, 1);
    atRepo.save(ate);
    atRepo.flush();

    final CareActorEntity ca1 = CareActorEntity.newEntity("Test", "Lkare", careActorHsa, cu);
    ca1.addRole(careActorRole);
    careActorRepo.save(ca1);
    careActorRepo.flush();

    final PatientEntity p2 = PatientEntity.newEntity("AppDemo", "Patient", "191112121212");
    p2.setPhoneNumber("0700000000");
    bean.save(p2);

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -30);
    HealthPlanEntity hp = HealthPlanEntity.newEntity(ca1, p2, "Auto", cal.getTime(), 6, DurationUnit.MONTH);
    hpRepo.save(hp);

    Frequency frequency = Frequency.unmarshal("1;1;2,18:15;6,07:00,19:00");
    ActivityDefinitionEntity ad = ActivityDefinitionEntity.newEntity(hp, ate, frequency, ca1);
    for (ActivityItemDefinitionEntity aid : ad.getActivityItemDefinitions()) {
        MeasurementDefinitionEntity md = (MeasurementDefinitionEntity) aid;
        if (md.getMeasurementType().getName().equals("Distans")) {
            md.setTarget(1200);
        }
    }
    adRepo.save(ad);
    hps.scheduleActivities(ad);
}

From source file:com.li.bus.utils.DateUtils.java

/**
 * ???//from   ww  w .ja  v  a  2  s.co m
 * @param date_begin
 * @param date_end
 * @return
 */
public static List<Date> getDates(Calendar date_begin, Calendar date_end) {
    List<Date> result = new ArrayList<Date>();
    Calendar temp = date_begin;
    while (temp.before(date_end)) {
        result.add(temp.getTime());
        temp.add(Calendar.DAY_OF_YEAR, 1);
    }
    return result;
}