List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:edu.harvard.iq.dvn.core.doi.DOIEZIdServiceBean.java
public static String generateTimeString() { StringBuffer guid = new StringBuffer(); // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime);/*from w w w .ja va 2 s . c om*/ guid.append(calendar.get(Calendar.YEAR)); guid.append(calendar.get(Calendar.DAY_OF_YEAR)); guid.append(calendar.get(Calendar.HOUR_OF_DAY)); guid.append(calendar.get(Calendar.MINUTE)); guid.append(calendar.get(Calendar.SECOND)); guid.append(calendar.get(Calendar.MILLISECOND)); double random = Math.random(); guid.append(random); return guid.toString(); }
From source file:org.hil.core.dao.hibernate.ChildrenVaccinationHistoryDaoHibernate.java
public ChildrenVaccinationHistory saveVaccinationHistory(ChildrenVaccinationHistory vaccinationEvent) { log.debug("Check before save vaccination event: " + vaccinationEvent.getChild().getId() + " | " + vaccinationEvent.getId() + " | " + vaccinationEvent.getVaccinated()); List<Number> temp1 = this.getChildAndVaccinationAndVaccinated(vaccinationEvent.getChild(), vaccinationEvent.getVaccination(), (short) 1); if (vaccinationEvent.getVaccinated().shortValue() == 0) { if (temp1 != null && temp1.size() > 0) this.setNotVaccinated(temp1); return vaccinationEvent; }// www.jav a2 s.c om if (vaccinationEvent.getVaccinated() == 1) { if (temp1 != null && temp1.size() > 0) { if (temp1.get(0).longValue() != vaccinationEvent.getId().longValue()) return vaccinationEvent; } } List<Number> temp0 = this.getChildAndVaccinationAndVaccinated(vaccinationEvent.getChild(), vaccinationEvent.getVaccination(), (short) 0); if (vaccinationEvent.getVaccinated() == 0) { if (temp1 != null && temp1.size() > 0) { if (temp1.get(0).longValue() != vaccinationEvent.getId().longValue()) return vaccinationEvent; } else { if (temp0 != null && temp0.size() > 0) { if (temp0.get(0).longValue() != vaccinationEvent.getId().longValue()) return vaccinationEvent; } } } boolean createNewVaccinationEvent = false; if (vaccinationEvent.getVaccinated() == 2) { if (temp1 != null && temp1.size() > 0) { if (temp1.get(0).longValue() == vaccinationEvent.getId().longValue()) return vaccinationEvent; } else { if (temp0 != null && temp0.size() > 0) { if (temp0.get(0).longValue() == vaccinationEvent.getId().longValue()) createNewVaccinationEvent = true; } } } log.debug("Saving vaccination event: " + vaccinationEvent.getChild().getId() + " | " + vaccinationEvent.getId() + " | " + vaccinationEvent.getVaccinated()); if (vaccinationEvent.getVaccination().getId() == 1 && vaccinationEvent.getVaccinated() == 1) { Calendar calendar = Calendar.getInstance(); calendar.setTime(vaccinationEvent.getChild().getDateOfBirth()); calendar.add(Calendar.DAY_OF_YEAR, 1); Date tmp = calendar.getTime(); if (vaccinationEvent.getDateOfImmunization().getTime() <= tmp.getTime()) vaccinationEvent.setOverdue(false); else vaccinationEvent.setOverdue(true); } vaccinationEvent.setModifiedTime(new Date()); vaccinationEvent = childrenVaccinationHistoryDao.save(vaccinationEvent); getSession().flush(); if (vaccinationEvent.getVaccinated() == 1) { temp0 = getChildAndVaccinationAndVaccinated(vaccinationEvent.getChild(), vaccinationEvent.getVaccination(), (short) 0); for (int c = 0; c < temp0.size(); c++) { childrenVaccinationHistoryDao.remove(childrenVaccinationHistoryDao.get(temp0.get(c).longValue())); } boolean finish = checkFinish(vaccinationEvent.getChild()); if (finish) { Date finDate = checkFinishDate(vaccinationEvent.getChild()); vaccinationEvent.getChild().setFinishedDate(finDate); childrenDao.save(vaccinationEvent.getChild()); } else { if (vaccinationEvent.getChild().getFinishedDate() != null) { vaccinationEvent.getChild().setFinishedDate(null); childrenDao.save(vaccinationEvent.getChild()); } } } else { boolean finish = checkFinish(vaccinationEvent.getChild()); if (!finish) { vaccinationEvent.getChild().setFinishedDate(null); childrenDao.save(vaccinationEvent.getChild()); } } if (createNewVaccinationEvent) { Children c = vaccinationEvent.getChild(); ChildrenVaccinationHistory newVH = new ChildrenVaccinationHistory(); newVH.setChild(c); newVH.setOverdue(false); newVH.setReasonIfMissed(""); newVH.setVaccinated((short) 0); newVH.setVaccination(vaccinationEvent.getVaccination()); newVH.setModifiedTime(new Date()); childrenVaccinationHistoryDao.save(newVH); } return vaccinationEvent; }
From source file:com.greenline.guahao.biz.util.DateUtils.java
/** * ???/* w w w . j a va 2s . c om*/ * * @param date * @return */ public static Date getLastDay(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_YEAR, 1); return calendar.getTime(); }
From source file:br.com.hslife.orcamento.service.ResumoEstatisticaService.java
/*** Implementao dos mtodos da interface ***/ public List<SaldoAtualConta> gerarSaldoAtualContas(boolean agendado, Usuario usuario) { // Declarao dos objetos List<SaldoAtualConta> saldoAtualContas = new ArrayList<>(); SaldoAtualConta saldoAtual = new SaldoAtualConta(); // Resgata todas as contas do usurio Set<Conta> contas = new HashSet<>(getContaService().buscarDescricaoOuTipoContaOuAtivoPorUsuario(null, new TipoConta[] {}, usuario, null)); // Traz as contas compartilhadas para com o usurio atualmente logado List<ContaCompartilhada> contasCompartilhadas = getContaCompartilhadaService() .buscarTodosPorUsuario(usuario); // Acrescenta no Set as contas compartilhadas dos demais usurios for (ContaCompartilhada contaCompartilhada : contasCompartilhadas) { contas.add(contaCompartilhada.getConta()); }//from w ww .j a v a2s .com // Itera todas as contas do usurio for (Conta conta : contas) { // Define a descrio da conta saldoAtual.setDescricaoConta(conta.getDescricao()); saldoAtual.setMoedaConta(conta.getMoeda()); saldoAtual.setTipoConta(conta.getTipoConta()); // Define a situao da conta saldoAtual.setAtivo(conta.isAtivo()); // Declara o critrio de busca CriterioBuscaLancamentoConta criterio = new CriterioBuscaLancamentoConta(); // Verifica se a conta do tipo CARTAO if (conta.getTipoConta().equals(TipoConta.CARTAO)) { // Seta o saldo do perodo com o limite do carto saldoAtual.setSaldoPeriodo(conta.getMoeda().isPadrao() ? conta.getCartaoCredito().getLimiteCartao() : Util.arredondar( conta.getCartaoCredito().getLimiteCartao() * conta.getMoeda().getValorConversao())); // Traz todos os lanamentos do carto que ainda no foram quitados criterio.setStatusLancamentoConta(new StatusLancamentoConta[] { StatusLancamentoConta.REGISTRADO, StatusLancamentoConta.AGENDADO }); // Seta a conta criterio.setConta(conta); } else { // Traz o ltimo perodo de fechamento da conta FechamentoPeriodo ultimoFechamento = getFechamentoPeriodoService() .buscarUltimoFechamentoConta(conta); if (ultimoFechamento == null) { saldoAtual.setSaldoPeriodo(conta.getMoeda().isPadrao() ? conta.getSaldoInicial() : Util.arredondar(conta.getSaldoInicial() * conta.getMoeda().getValorConversao())); } else { saldoAtual.setSaldoPeriodo(conta.getMoeda().isPadrao() ? ultimoFechamento.getSaldo() : Util.arredondar(ultimoFechamento.getSaldo() * conta.getMoeda().getValorConversao())); } // Traz os lanamentos da data de fechamento em diante // Se a opo de agendado estiver marcada, traz os lanamentos agendados if (agendado) criterio.setStatusLancamentoConta(new StatusLancamentoConta[] { StatusLancamentoConta.AGENDADO, StatusLancamentoConta.REGISTRADO, StatusLancamentoConta.QUITADO }); else criterio.setStatusLancamentoConta(new StatusLancamentoConta[] { StatusLancamentoConta.REGISTRADO, StatusLancamentoConta.QUITADO }); criterio.setConta(conta); if (ultimoFechamento == null) { criterio.setDataInicio(conta.getDataAbertura()); } else { Calendar temp = Calendar.getInstance(); temp.setTime(ultimoFechamento.getData()); temp.add(Calendar.DAY_OF_YEAR, 1); criterio.setDataInicio(temp.getTime()); } } // Para os cartes de dbito, traz somente os lanamentos do ms corrente if (conta.getTipoConta().equals(TipoConta.CARTAO) && conta.getCartaoCredito().getTipoCartao().equals(TipoCartao.DEBITO)) { criterio.setDataInicio(Util.primeiroDiaMesAtual()); criterio.setDataFim(Util.ultimoDiaMesAtual()); } List<LancamentoConta> lancamentos = getLancamentoContaService().buscarPorCriterioBusca(criterio); // Calcula o saldo dos lanamentos e registra no saldo atual saldoAtual.setSaldoRegistrado(LancamentoContaUtil.calcularSaldoLancamentosComConversao(lancamentos)); // Calcula o saldo atual da conta saldoAtual.setSaldoAtual(saldoAtual.getSaldoPeriodo() + saldoAtual.getSaldoRegistrado()); // Adiciona na lista de saldos da conta saldoAtualContas.add(saldoAtual); saldoAtual = new SaldoAtualConta(); } // Retorna a lista de saldos atuais return this.incorporarInvestimentos(saldoAtualContas); }
From source file:com.grepcurl.random.BaseGenerator.java
public Date randomDateInLastNDays(int n) { Date temp = new Date(); Calendar c = Calendar.getInstance(); c.setTime(temp);/* w ww .j a va 2s . c o m*/ c.add(Calendar.DAY_OF_YEAR, randomInt(-1 * n, -1)); Date startDate = c.getTime(); String startDateString = _sdf.format(startDate); try { return _sdf.parse(startDateString); } catch (ParseException e) { e.printStackTrace(); throw new RuntimeException("Internal error formatting date during JUnit test."); } }
From source file:com.huateng.ebank.framework.util.DateUtil.java
/** * //w w w .j av a 2 s . com * * @param startDate * @param endDate * @return */ public static int getDaysBetween(Date startDate, Date endDate) { Calendar calendarStartDate = Calendar.getInstance(); Calendar calendarEndDate = Calendar.getInstance(); // calendarStartDate.setTime(startDate); calendarEndDate.setTime(endDate); if (startDate.after(endDate)) { Calendar swap = calendarStartDate; calendarStartDate = calendarEndDate; calendarEndDate = swap; } int days = calendarEndDate.get(Calendar.DAY_OF_YEAR) - calendarStartDate.get(Calendar.DAY_OF_YEAR); int y2 = calendarEndDate.get(Calendar.YEAR); while (calendarStartDate.get(Calendar.YEAR) < y2) { days += calendarStartDate.getActualMaximum(Calendar.DAY_OF_YEAR); calendarStartDate.add(Calendar.YEAR, 1); } return days; }
From source file:es.ficonlan.web.backend.test.eventservice.EventServiceTest.java
@Test public void testAddActivity() throws ServiceException, InstanceException { Session anonymousSession = userService.newAnonymousSession(); Session s = userService.login(anonymousSession.getSessionId(), ADMIN_LOGIN, ADMIN_PASS); Calendar dateStart = Calendar.getInstance(); Calendar dateEnd = Calendar.getInstance(); dateEnd.add(Calendar.DAY_OF_YEAR, 1); Event event = new Event(0, "FicOnLan 2014", "FicOnLan 2014", 150, dateStart, dateEnd, dateStart, dateEnd, null, null, null, null, null); eventDao.save(event);/* ww w .java 2s .c om*/ Activity activity = eventService.addActivity(s.getSessionId(), event.getEventId(), new Activity(event, "Torneo de Lol", "Torneo de Lol", 10, ActivityType.Tournament, true, dateStart, dateEnd, dateStart, dateEnd)); assertTrue(activityDao.find(activity.getActivityId()).getActivityId() == activity.getActivityId()); }
From source file:org.activiti.crystalball.simulator.OptimizeBottleneckTest.java
/** * run simulation for 30 days and generate report * /*from w w w . j a v a 2 s.c o m*/ * @param appContext * @throws Exception */ protected void runSimulation(AbstractApplicationContext appContext, String instancesGeneratedImage, String dueDateGeneratedImage) throws Exception { SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); Calendar c = Calendar.getInstance(); c.clear(); c.set(2013, 1, 1); Date startDate = c.getTime(); // add 30 days to start day c.add(Calendar.DAY_OF_YEAR, 30); Date finishDate = c.getTime(); // run simulation for 30 days @SuppressWarnings("unused") List<ResultEntity> resultEventList = simRun.execute(startDate, finishDate); RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService"); String processDefinitionId = simRepositoryService.createProcessDefinitionQuery() .processDefinitionKey(PROCESS_KEY).singleResult().getId(); // GENERATE REPORTS // instances report AbstractProcessEngineGraphGenerator generator = (AbstractProcessEngineGraphGenerator) appContext .getBean("reportGenerator"); generator.generateReport(processDefinitionId, startDate, finishDate, instancesGeneratedImage); // after due date report generator = (AbstractProcessEngineGraphGenerator) appContext.getBean("dueDateReportGenerator"); generator.generateReport(processDefinitionId, startDate, finishDate, dueDateGeneratedImage); }
From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java
private boolean isItTomorrow(Integer today) { Calendar calendarTest = Calendar.getInstance(); return today != (calendarTest.get(Calendar.DAY_OF_YEAR)); }
From source file:controllers.core.TimesheetController.java
/** * Save the weekly timesheet.//from w ww .jav a 2 s. com */ @Restrict({ @Group(IMafConstants.TIMESHEET_ENTRY_PERMISSION) }) public Result weeklySave() { String[] dataString = request().body().asFormUrlEncoded().get("data"); try { JSONObject dataJson = new JSONObject(dataString[0]); // get the report Long reportId = dataJson.getLong("reportId"); TimesheetReport report = TimesheetDao.getTimesheetReportById(reportId); // create the date format SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // get the actor Actor actor = getCurrentActor(); // check the report belongs to the sign-in user if (!report.actor.id.equals(actor.id)) { return forbidden(views.html.error.access_forbidden.render("")); } // check the report is editable if (!report.isEditable()) { Utilities.sendErrorFlashMessage(Msg.get("core.timesheet.fill.save.error.non_editable")); return redirect( controllers.core.routes.TimesheetController.weeklyFill(sdf.format(report.startDate))); } Ebean.beginTransaction(); try { // get the entries JSONArray entriesJson = dataJson.getJSONArray("entries"); for (int i = 0; i < entriesJson.length(); i++) { JSONObject entryJson; try { entryJson = entriesJson.getJSONObject(i); } catch (JSONException e) { entryJson = null; } if (entryJson != null) { // get the attributes boolean inDB = entryJson.getBoolean("inDB"); Boolean toRemove; try { toRemove = entryJson.getBoolean("toRemove"); } catch (JSONException e) { toRemove = null; } Long entryId; try { entryId = entryJson.getLong("entryId"); } catch (JSONException e) { entryId = null; } Long portfolioEntryId; try { portfolioEntryId = entryJson.getLong("portfolioEntryId"); } catch (JSONException e) { portfolioEntryId = null; } Long packageId; try { packageId = entryJson.getLong("packageId"); } catch (JSONException e) { packageId = null; } Long activityId; try { activityId = entryJson.getLong("activityId"); } catch (JSONException e) { activityId = null; } // get the logs JSONArray logsJson = entryJson.getJSONArray("logs"); if (logsJson.length() == 7) { TimesheetEntry entry = null; if (inDB) { entry = TimesheetDao.getTimesheetEntryById(entryId); } else { entry = new TimesheetEntry(); entry.timesheetReport = report; } if (inDB && toRemove) { entry.doDelete(); } else { entry.portfolioEntry = null; entry.portfolioEntryPlanningPackage = null; entry.timesheetActivity = null; if (portfolioEntryId != null) { // initiative entry.portfolioEntry = PortfolioEntryDao.getPEById(portfolioEntryId); if (packageId != null) { entry.portfolioEntryPlanningPackage = PortfolioEntryPlanningPackageDao .getPEPlanningPackageById(packageId); } } else { // activity entry.timesheetActivity = TimesheetDao.getTimesheetActivityById(activityId); } entry.save(); for (int j = 0; j < logsJson.length(); j++) { JSONObject logJson = logsJson.getJSONObject(j); // get the attributes double hours = logJson.getDouble("hours"); Long logId; try { logId = logJson.getLong("logId"); } catch (JSONException e) { logId = null; } TimesheetLog log = null; if (inDB) { log = TimesheetDao.getTimesheetLogById(logId); } else { log = new TimesheetLog(); log.timesheetEntry = entry; Calendar cal = Calendar.getInstance(); cal.setTime(report.startDate); cal.add(Calendar.DAY_OF_YEAR, j); log.logDate = cal.getTime(); } log.hours = hours; log.save(); } } } } } Ebean.commitTransaction(); } catch (Exception e) { Ebean.rollbackTransaction(); return ControllersUtils.logAndReturnUnexpectedError(e, log, getConfiguration(), getI18nMessagesPlugin()); } Utilities.sendSuccessFlashMessage(Msg.get("core.timesheet.fill.save.successful")); return redirect(controllers.core.routes.TimesheetController.weeklyFill(sdf.format(report.startDate))); } catch (Exception e) { return ControllersUtils.logAndReturnUnexpectedError(e, log, getConfiguration(), getI18nMessagesPlugin()); } }