List of usage examples for java.util GregorianCalendar add
@Override public void add(int field, int amount)
From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java
public SynchronizedDescriptiveStatistics getDailyStats(Date startDate, Date endDate, Long hospital, String filter, boolean includeWeekends, boolean ptflag, boolean scheduledFlag) { SynchronizedDescriptiveStatistics stats = new SynchronizedDescriptiveStatistics(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(endDate);/* ww w . j a v a 2 s. c om*/ gc.add(Calendar.DATE, -1); List<Object[]> counts = getDailyCounts(startDate, gc.getTime(), hospital, filter, includeWeekends, ptflag, scheduledFlag); for (Object[] item : counts) { stats.addValue(((Long) item[1]).doubleValue()); } return stats; }
From source file:main.UIController.java
public void convertToGregorian() { UI window = this.getUi(); String errorNoLoa = "Please insert a loa."; String errorLoaNotNumeric = "Please insert the loa as a numeric value."; String errorYearNotValid = "Please insert a valid loa (from 1 to 144)."; String errorDayNotRead = "Sorry, the day could not be read."; JComboBox yen = window.getYen(); JTextField loa = window.getLoa(); JComboBox period = window.getPeriod(); JComboBox day = window.getDayOfLoa(); JCheckBox beforeMidnight = window.getBeforeMidnight(); JTextPane result = window.getResGregorian(); int yenNum = yen.getSelectedIndex() + 1; String value = loa.getText(); if (!value.isEmpty()) { try {/*from ww w . j a v a2 s . co m*/ int loaNum = Integer.parseInt(value); if (loaNum > 0 && loaNum <= 144) { int periodNum = period.getSelectedIndex() + 1; ImladrisCalendar cal = new ImladrisCalendar(); boolean success = false; if (periodNum == ImladrisCalendar.YESTARE || periodNum == ImladrisCalendar.METTARE) { success = true; cal = new ImladrisCalendar(cal.intToRoman(yenNum), loaNum, periodNum); } else { int dayNum = 0; if (day.isEnabled()) { success = true; dayNum = day.getSelectedIndex() + 1; cal = new ImladrisCalendar(cal.intToRoman(yenNum), loaNum, periodNum, dayNum); } else { result.setText(errorDayNotRead); } } if (success) { GregorianCalendar gcal = cal.getGregorian(); if (beforeMidnight.isSelected()) { gcal.add(GregorianCalendar.DAY_OF_YEAR, -1); } String gstr = this.gregorianToString(gcal); result.setText(gstr); } } else { result.setText(errorYearNotValid); } } catch (NumberFormatException e) { result.setText(errorLoaNotNumeric); } } else { result.setText(errorNoLoa); } }
From source file:mekhq.campaign.mission.Contract.java
/** * Get the number of months left in this contract after the given date. Partial months are counted as * full months./* ww w . j a v a 2 s .c o m*/ * * @param date * @return */ public int getMonthsLeft(Date date) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.MONTH, 1); date = cal.getTime(); int monthsLeft = 0; while (date.before(endDate) || date.equals(endDate)) { monthsLeft++; cal.add(Calendar.MONTH, 1); date = cal.getTime(); } return monthsLeft; }
From source file:com.sapienter.jbilling.client.payment.PaymentCrudAction.java
@Override protected PaymentDTOEx doEditFormToDTO() { PaymentDTOEx dto = new PaymentDTOEx(); // the id, only for payment edits dto.setId((Integer) myForm.get(FIELD_ID) == null ? 0 : (Integer) myForm.get(FIELD_ID)); // set the amount dto.setAmount(string2decimal((String) myForm.get(FIELD_AMOUNT))); // set the date dto.setPaymentDate(parseDate(FIELD_GROUP_DATE, "payment.date")); final String payMethod = (String) myForm.get(FIELD_PAY_METHOD); if ("cheque".equals(payMethod)) { // create the cheque dto PaymentInfoChequeDTO chequeDto = new PaymentInfoChequeDTO(); chequeDto.setBank((String) myForm.get(FIELD_CHEQUE_BANK)); chequeDto.setNumber((String) myForm.get(FIELD_CHEQUE_NUMBER)); chequeDto.setDate(parseDate(FIELD_GROUP_CHEQUE_DATE, "payment.cheque.date")); // set the cheque dto.setCheque(chequeDto);//from w w w . j av a 2s . c o m dto.setPaymentMethod(new PaymentMethodDTO(Constants.PAYMENT_METHOD_CHEQUE)); // validate required fields required(chequeDto.getNumber(), "payment.cheque.number"); required(chequeDto.getDate(), "payment.cheque.date"); // cheques now are never process realtime (may be later will support // electronic cheques dto.setPaymentResult(new PaymentResultDTO(Constants.RESULT_ENTERED)); session.setAttribute("tmp_process_now", new Boolean(false)); } else if ("cc".equals(payMethod)) { String ccNumber = (String) myForm.get(FIELD_CC_NUMBER); boolean masked = false; // check if cc number is masked if (isMaskedCreditCard(ccNumber)) { LOG.debug("cc no. masked; " + "getting user's existing cc details"); // try to get existing cc details UserDTOEx user = getSessionUser(); CreditCardDTO existingCcDTO = user.getCreditCard(); if (existingCcDTO != null) { String existingNumber = existingCcDTO.getNumber(); // check that four last digits match if (existingNumber.substring(existingNumber.length() - 4) .equals(ccNumber.substring(ccNumber.length() - 4))) { LOG.debug("got a matching masked cc number"); masked = true; ccNumber = existingNumber; } } } // do cc validation for non-masked numbers if (!masked) { validateCreditCard(); // return if credit card validation failed if (!errors.isEmpty()) { return null; } } CreditCardDTO ccDto = new CreditCardDTO(); ccDto.setNumber(ccNumber); ccDto.setName((String) myForm.get(FIELD_CC_NAME)); myForm.set(FIELD_GROUP_CC_EXPIRY + "_day", "01"); // to complete the date ccDto.setCcExpiry(parseDate(FIELD_GROUP_CC_EXPIRY, "payment.cc.date")); if (ccDto.getCcExpiry() != null) { // the expiry can't be past today GregorianCalendar cal = new GregorianCalendar(); cal.setTime(ccDto.getCcExpiry()); cal.add(GregorianCalendar.MONTH, 1); // add 1 month if (Calendar.getInstance().getTime().after(cal.getTime())) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("creditcard.error.expired", "payment.cc.date")); } } dto.setCreditCard(ccDto); // this will be checked when the payment is sent session.setAttribute("tmp_process_now", (Boolean) myForm.get(FIELD_PROCESS_NOW)); // validate required fields required(ccDto.getNumber(), "payment.cc.number"); required(ccDto.getCcExpiry(), "payment.cc.date"); required(ccDto.getName(), "payment.cc.name"); // make sure that the cc is valid before trying to get // the payment method from it if (errors.isEmpty()) { dto.setPaymentMethod(new PaymentMethodDTO(Util.getPaymentMethod(ccDto.getNumber()))); } } else if ("ach".equals(payMethod)) { AchDTO ach = new AchDTO(); ach.setAbaRouting((String) myForm.get(FIELD_ACH_ABA_CODE)); ach.setBankAccount((String) myForm.get(FIELD_ACH_ACCOUNT_NUMBER)); ach.setAccountType((Integer) myForm.get(FIELD_ACH_ACCOUNT_TYPE)); ach.setBankName((String) myForm.get(FIELD_ACH_BANK_NAME)); ach.setAccountName((String) myForm.get(FIELD_ACH_ACCOUNT_NAME)); dto.setAch(ach); //this will be checked when the payment is sent session.setAttribute("tmp_process_now", new Boolean(true)); // since it is one big form for all methods, we need to // validate the required manually required(ach.getAbaRouting(), "ach.aba.prompt"); required(ach.getBankAccount(), "ach.account_number.prompt"); required(ach.getBankName(), "ach.bank_name.prompt"); required(ach.getAccountName(), "ach.account_name.prompt"); if (errors.isEmpty()) { dto.setPaymentMethod(new PaymentMethodDTO(Constants.PAYMENT_METHOD_ACH)); } } // set the customer id selected in the list (not the logged) dto.setUserId((Integer) session.getAttribute(Constants.SESSION_USER_ID)); // specify if this is a normal payment or a refund dto.setIsRefund(session.getAttribute("jsp_is_refund") == null ? 0 : 1); LOG.debug("refund = " + dto.getIsRefund()); // set the selected payment for refunds if (dto.getIsRefund() == 1) { PaymentDTOEx refundPayment = (PaymentDTOEx) session.getAttribute(Constants.SESSION_PAYMENT_DTO); /* * Right now, to process a real-time credit card refund it has to be to * refund a previously done credit card payment. This could be * changed, to say, refund using the customer's credit card no matter * how the guy paid initially. But this might be subjet to the * processor features. * */ ActionError realTimeNoPayment = null; boolean processNow = (Boolean) myForm.get(FIELD_PROCESS_NOW); if ("cc".equals(payMethod) && processNow) { if (refundPayment == null || refundPayment.getCreditCard() == null || refundPayment.getAuthorization() == null || !Constants.RESULT_OK.equals(refundPayment.getPaymentResult().getId())) { realTimeNoPayment = new ActionError(// "refund.error.realtimeNoPayment", "payment.cc.processNow"); } } if (realTimeNoPayment != null) { errors.add(ActionErrors.GLOBAL_ERROR, realTimeNoPayment); } else { dto.setPayment(refundPayment); } // refunds, I need to manually delete the list, because // in the end only the LIST_PAYMENT will be removed session.removeAttribute(Constants.SESSION_LIST_KEY + Constants.LIST_TYPE_REFUND); } // last, set the currency //If a related document is // set (invoice/payment) it'll take it from there. Otherwise it // wil inherite the one from the user Integer currencyId = (Integer) myForm.get(FIELD_CURRENCY); dto.setCurrency(currencyId != null ? new CurrencyDTO((Integer) myForm.get(FIELD_CURRENCY)) : null); if (dto.getCurrency() == null) { dto.setCurrency(getUser(dto.getUserId()).getCurrency()); } if (errors.isEmpty()) { // verify that this entity actually accepts this kind of //payment method if (!myPaymentSession.isMethodAccepted((Integer) session.getAttribute(Constants.SESSION_ENTITY_ID_KEY), dto.getPaymentMethod().getId())) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("payment.error.notAccepted", "payment.method")); } } //LOG.debug("now payment methodId = " + dto.getPaymentMethod().getId()); LOG.debug("now paymentDto = " + dto); return dto; }
From source file:org.flowable.job.service.impl.asyncexecutor.DefaultJobManager.java
protected void internalCreateLockedAsyncJob(JobEntity jobEntity, boolean exclusive) { fillDefaultAsyncJobInfo(jobEntity, exclusive); GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(jobServiceConfiguration.getClock().getCurrentTime()); gregorianCalendar.add(Calendar.MILLISECOND, getAsyncExecutor().getAsyncJobLockTimeInMillis()); jobEntity.setLockExpirationTime(gregorianCalendar.getTime()); jobEntity.setLockOwner(getAsyncExecutor().getLockOwner()); }
From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java
@TargetApi(Build.VERSION_CODES.KITKAT) private void updateNextDayAlarm() { Intent intent = new Intent(this, NotificationUpdaterService.class); intent.setAction(ACTION_NEXT_DAY);//from w ww . j av a2 s . com mDateChangePendingIntent = PendingIntent.getService(this, 0, intent, 0); // set alarm to update the next day GregorianCalendar tomorrow = new GregorianCalendar(); tomorrow.add(Calendar.DAY_OF_YEAR, 1); tomorrow.set(Calendar.HOUR_OF_DAY, 0); tomorrow.set(Calendar.MINUTE, 0); tomorrow.set(Calendar.SECOND, 0); tomorrow.set(Calendar.MILLISECOND, 0); AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { alarmManager.setWindow(AlarmManager.RTC, tomorrow.getTimeInMillis(), 1000, mDateChangePendingIntent); } else { alarmManager.set(AlarmManager.RTC, tomorrow.getTimeInMillis(), mDateChangePendingIntent); } }
From source file:com.sapienter.jbilling.server.process.AgeingBL.java
/** * Will move the user one step forward in the ageing proces ONLY IF * the user has been long enough in the present status. (for a user * in active status, it always moves it to the first ageing step). * @param userId//from ww w . j a v a 2 s . c o m * @throws NamingException * @throws SessionInternalError */ public void age(UserDTO user, Date today) throws NamingException, SessionInternalError { LOG.debug("Ageing user:" + user.getUserId()); Integer status = user.getStatus().getId(); Integer nextStatus = null; if (status.equals(UserDTOEx.STATUS_ACTIVE)) { // welcome to the ageing process nextStatus = getNextStep(user.getEntity(), UserDTOEx.STATUS_ACTIVE); } else { LOG.debug("she's already in the ageing"); // this guy is already in the ageing AgeingEntityStepDTO step = new AgeingEntityStepDAS().findStep(user.getEntity().getId(), status); if (step != null) { ageing = ageingDas.find(step.getId()); // verify if it is time for another notch GregorianCalendar cal = new GregorianCalendar(); Date lastChange = user.getLastStatusChange(); if (lastChange == null) { lastChange = user.getCreateDatetime(); } cal.setTime(lastChange); cal.add(Calendar.DATE, ageing.getDays()); LOG.debug("last time + days=" + cal.getTime() + " today " + today + "compare=" + cal.getTime().compareTo(today)); if (cal.getTime().compareTo(today) <= 0) { nextStatus = getNextStep(user.getEntity(), user.getStatus().getId()); } else { return; } } else { // this user is an ageing status that has been removed. // may be this is a bug, and a currently-in-use status // should not be removable. // Now it will simple jump to the next status. nextStatus = getNextStep(user.getEntity(), user.getStatus().getId()); } } if (nextStatus != null) { setUserStatus(null, user.getUserId(), nextStatus, today); } else { eLogger.warning(user.getEntity().getId(), user.getUserId(), user.getUserId(), EventLogger.MODULE_USER_MAINTENANCE, EventLogger.NO_FURTHER_STEP, Constants.TABLE_BASE_USER); } }
From source file:org.flowable.job.service.impl.asyncexecutor.DefaultJobManager.java
protected JobEntity createExecutableJobFromOtherJob(AbstractRuntimeJobEntity job) { JobEntity executableJob = jobServiceConfiguration.getJobEntityManager().create(); copyJobInfo(executableJob, job);//w w w. j av a 2 s . c o m if (isAsyncExecutorActive()) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(jobServiceConfiguration.getClock().getCurrentTime()); gregorianCalendar.add(Calendar.MILLISECOND, getAsyncExecutor().getTimerLockTimeInMillis()); executableJob.setLockExpirationTime(gregorianCalendar.getTime()); executableJob.setLockOwner(getAsyncExecutor().getLockOwner()); } return executableJob; }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Calculates the next scheduled time after now. * // ww w . j a v a 2 s . co m * @return The next scheduled time after now. * @throws ImplementationException * Almost any kind of error. */ public GregorianCalendar nextScheduledTime() throws ImplementationExceptionResponse { GregorianCalendar cal = new GregorianCalendar(); // start at the next second to avoid multiple results cal.add(SECOND, 1); return nextScheduledTime(cal); }
From source file:com.ephesoft.dcma.workflows.service.engine.impl.EngineServiceImpl.java
@Override @Transactional/*from ww w. j a v a 2 s. c om*/ public JobEntity lockJob(final CommandContext commandContext, final JobEntity job, String lockOwner, final int lockTimeInMillis) { JobEntity modifiedJobEntity; // Providing check again before locking a job and using activiti command listener class for reset retry count for job. if (EphesoftStringUtil.isNullOrEmpty(job.getLockOwner())) { String jobId = job.getId(); resetJobRetries(jobId, WorkflowConstants.MAX_NUMBER_OF_JOB_RETRIES); modifiedJobEntity = commandContext.getJobEntityManager().findJobById(jobId); GregorianCalendar gregorianCalendar = new GregorianCalendar(); Date currentTime = getCurrentTime(commandContext); gregorianCalendar.setTime(currentTime); gregorianCalendar.add(Calendar.MILLISECOND, lockTimeInMillis); Date date = gregorianCalendar.getTime(); LOGGER.info("Trying to obtain a lock for job with id: ", jobId, " with expiration time: ", timeFormat.format(date), " by lock owner: ", lockOwner); modifiedJobEntity.setLockOwner(lockOwner); modifiedJobEntity.setLockExpirationTime(date); } else { modifiedJobEntity = null; } return modifiedJobEntity; }