List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. 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);/*from w w w .ja v a2s . 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:com.glaf.core.util.DateUtils.java
/** * ?/* w ww .java 2s.c o m*/ * * @param date * @param day * @return */ public static Date getDateBefore(Date date, int day) { Calendar now = Calendar.getInstance(); now.setTime(date); now.set(Calendar.DATE, now.get(Calendar.DATE) - day); return now.getTime(); }
From source file:eionet.gdem.dcm.business.BackupManager.java
/** * Remove backup files and refereces in database * * @param nofDays/*from ww w . j av a 2 s.c o m*/ * - number of days to keep * @return * @throws DCMException */ public int purgeBackup(int nofDays) throws DCMException { int result = 0; Calendar purgeDate = Calendar.getInstance(); purgeDate.add(Calendar.DATE, -nofDays); SimpleDateFormat sf = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); LOGGER.info("Purge backup files created before: " + sf.format(new Date(purgeDate.getTimeInMillis()))); long purgeDateInMillis = purgeDate.getTimeInMillis(); Timestamp ts = new Timestamp(purgeDateInMillis); File backupFolder = new File(Properties.queriesFolder, Constants.BACKUP_FOLDER_NAME); if (backupFolder.exists() && backupFolder.isDirectory()) { File[] files = backupFolder.listFiles(); for (int i = 0; i < files.length; i++) { String fileName = files[i].getName(); // check if it is backup file if (!files[i].isFile() || !fileName.startsWith(Constants.BACKUP_FILE_PREFIX)) { continue; } int start = fileName.indexOf("_", Constants.BACKUP_FILE_PREFIX.length()); int end = fileName.lastIndexOf("."); String fileTimestamp = fileName.substring(start + 1, end); long lFileTimestamp = 0; try { lFileTimestamp = Long.parseLong(fileTimestamp); } catch (ClassCastException e) { continue; } if (lFileTimestamp < purgeDateInMillis) { try { files[i].delete(); result++; } catch (Exception ioe) { LOGGER.error("Unable to delete backup file: " + files[i].getPath(), ioe); } } } } LOGGER.info("Number of back files deleted: " + result); // remove database rows try { backupDao.removeBackupsOlderThan(ts); } catch (Exception e) { // e.printStackTrace(); LOGGER.error("Error removing backups.", e); throw new DCMException(BusinessConstants.EXCEPTION_GENERAL); } return result; }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static Date getTomorrowDate() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); //For tomorrow return DateUtils.truncate(calendar.getTime(), Calendar.DATE); }
From source file:eu.trentorise.smartcampus.permissionprovider.manager.RegistrationManager.java
public Registration register(String name, String surname, String email, String password, String lang) throws RegistrationException { if (!StringUtils.hasText(name) || !StringUtils.hasText(surname) || !StringUtils.hasText(email) || !StringUtils.hasText(password)) { throw new InvalidDataException(); }//from w w w. j a v a2 s.com if (lang == null) { lang = "en"; } Registration existing = getUserByEmail(email); if (existing != null) { throw new AlreadyRegisteredException(); } Registration reg = new Registration(); try { reg.setName(name); reg.setSurname(surname); reg.setEmail(email); reg.setConfirmed(false); Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, 1); reg.setConfirmationDeadline(c.getTime()); String key = generateKey(); reg.setConfirmationKey(key); reg.setPassword(PasswordHash.createHash(password)); reg.setLang(lang); repository.save(reg); sendConfirmationMail(reg, key); return reg; } catch (Exception e) { //repository.delete(reg); e.printStackTrace(); throw new RegistrationException(e); } }
From source file:py.una.pol.karaku.test.test.controller.KarakuRangeReportControllerTest.java
private Date getDate(int day, int month, int year) { Calendar c = Calendar.getInstance(); c.set(Calendar.DATE, day); c.set(Calendar.MONTH, month - 1); c.set(Calendar.YEAR, year);/*from w w w .j av a 2 s .c o m*/ return c.getTime(); }
From source file:org.sharetask.service.StatisticsServiceImpl.java
private StatisticsDataDTO getStatisticsPerLastWeek() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); Date date = DateUtils.truncate(calendar.getTime(), Calendar.DATE); return new StatisticsDataDTO.Builder().usersCount(userInformationRepository.getCountCreatedAfter(date)) .workspacesCount(workspaceRepository.getCountCreatedAfter(date)) .tasksCount(taskRepository.getCountCreatedAfter(date)).build(); }
From source file:carrental.beans.billing.BillingBean.java
private Date simulateReturnDate(ReturnProtocol returnProtocol) { Calendar c = Calendar.getInstance(); c.setTime(returnProtocol.getReturnDate()); int randomNumberOfDays = (int) (new Random().nextGaussian() * 4 + 23); c.add(Calendar.DATE, randomNumberOfDays); // Adding a randomNumberOfDays for simulationPurposes Date newReturnDate = c.getTime(); return newReturnDate; }
From source file:cz.muni.fi.pv168.dressroomAppGui.MainMenuFrame.java
public java.sql.Date getSqlDate(java.util.Date date, int daysMove) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from ww w . java2s . c o m cal.add(Calendar.DATE, daysMove); return new java.sql.Date(cal.getTime().getTime()); }
From source file:com.cws.esolutions.security.quartz.PasswordExpirationNotifier.java
/** * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) *//* ww w . jav a 2 s. c o m*/ public void execute(final JobExecutionContext context) { final String methodName = PasswordExpirationNotifier.CNAME + "#execute(final JobExecutionContext jobContext)"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("JobExecutionContext: {}", context); } final Map<String, Object> jobData = context.getJobDetail().getJobDataMap(); if (DEBUG) { DEBUGGER.debug("jobData: {}", jobData); } try { UserManager manager = UserManagerFactory .getUserManager(bean.getConfigData().getSecurityConfig().getUserManager()); if (DEBUG) { DEBUGGER.debug("UserManager: {}", manager); } List<String[]> accounts = manager.listUserAccounts(); if (DEBUG) { DEBUGGER.debug("accounts: {}", accounts); } if ((accounts == null) || (accounts.size() == 0)) { return; } Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 30); Long expiryTime = cal.getTimeInMillis(); if (DEBUG) { DEBUGGER.debug("Calendar: {}", cal); DEBUGGER.debug("expiryTime: {}", expiryTime); } for (String[] account : accounts) { if (DEBUG) { DEBUGGER.debug("Account: {}", (Object) account); } List<Object> accountDetail = manager.loadUserAccount(account[0]); if (DEBUG) { DEBUGGER.debug("List<Object>: {}", accountDetail); } try { Email email = new SimpleEmail(); email.setHostName((String) jobData.get("mailHost")); email.setSmtpPort(Integer.parseInt((String) jobData.get("portNumber"))); if ((Boolean) jobData.get("isSecure")) { email.setSSLOnConnect(true); } if ((Boolean) jobData.get("isAuthenticated")) { email.setAuthenticator(new DefaultAuthenticator((String) jobData.get("username"), PasswordUtils.decryptText((String) (String) jobData.get("password"), (String) jobData.get("salt"), secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(), secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(), systemConfig.getEncoding()))); } email.setFrom((String) jobData.get("emailAddr")); email.addTo((String) accountDetail.get(6)); email.setSubject((String) jobData.get("messageSubject")); email.setMsg(String.format((String) jobData.get("messageBody"), (String) accountDetail.get(4))); if (DEBUG) { DEBUGGER.debug("SimpleEmail: {}", email); } email.send(); } catch (EmailException ex) { ERROR_RECORDER.error(ex.getMessage(), ex); } catch (SecurityException sx) { ERROR_RECORDER.error(sx.getMessage(), sx); } } } catch (UserManagementException umx) { ERROR_RECORDER.error(umx.getMessage(), umx); } }