List of usage examples for java.util Date getMonth
@Deprecated public int getMonth()
From source file:org.apache.lens.cube.metadata.UpdatePeriod.java
public Date truncate(Date date) { switch (this) { case WEEKLY:// ww w . j a va 2 s . co m Date truncDate = DateUtils.truncate(date, Calendar.DAY_OF_MONTH); Calendar cal = Calendar.getInstance(); cal.setTime(truncDate); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); return cal.getTime(); case QUARTERLY: Date dt = DateUtils.truncate(date, this.calendarField()); dt.setMonth(dt.getMonth() - (dt.getMonth() % 3)); return dt; default: return DateUtils.truncate(date, this.calendarField()); } }
From source file:org.libreplan.web.costcategories.ResourcesCostCategoryAssignmentController.java
/** * Binds Datebox "init date" to the corresponding attribute of a {@link ResourcesCostCategoryAssignment} * * @param dateBoxInitDate//from www . jav a2 s . co m * @param hourCost */ private void bindDateboxEndDate(final Datebox dateBoxEndDate, final ResourcesCostCategoryAssignment assignment) { Util.bind(dateBoxEndDate, new Util.Getter<Date>() { @Override public Date get() { LocalDate dateTime = assignment.getEndDate(); if (dateTime != null) { return new Date(dateTime.getYear() - 1900, dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth()); } return null; } }, new Util.Setter<Date>() { @Override public void set(Date value) { if (value != null) { assignment.setEndDate( new LocalDate(value.getYear() + 1900, value.getMonth() + 1, value.getDate())); } else { assignment.setEndDate(null); } } }); }
From source file:org.libreplan.web.costcategories.ResourcesCostCategoryAssignmentController.java
/** * Binds Datebox "init date" to the corresponding attribute of a {@link ResourcesCostCategoryAssignment} * * @param dateBoxInitDate/*from ww w. j av a 2s . c o m*/ * @param hourCost */ private void bindDateboxInitDate(final Datebox dateBoxInitDate, final ResourcesCostCategoryAssignment assignment) { Util.bind(dateBoxInitDate, new Util.Getter<Date>() { @Override public Date get() { LocalDate dateTime = assignment.getInitDate(); if (dateTime != null) { return new Date(dateTime.getYear() - 1900, dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth()); } return null; } }, new Util.Setter<Date>() { @Override public void set(Date value) { if (value != null) { assignment.setInitDate( new LocalDate(value.getYear() + 1900, value.getMonth() + 1, value.getDate())); } else { assignment.setInitDate(null); } } }); }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ?/*from w w w . java2 s . c o m*/ * * @param date * @return */ @SuppressWarnings("deprecation") public static int getQuarter(Date date) { if (date.getMonth() == 0 || date.getMonth() == 1 || date.getMonth() == 2) { return 1; } else if (date.getMonth() == 3 || date.getMonth() == 4 || date.getMonth() == 5) { return 2; } else if (date.getMonth() == 6 || date.getMonth() == 7 || date.getMonth() == 8) { return 3; } else if (date.getMonth() == 9 || date.getMonth() == 10 || date.getMonth() == 11) { return 4; } else { return 0; } }
From source file:org.hil.vaccinationday.service.impl.VaccinationDayManagerImpl.java
public void updateChildrenVaccinationDay(VaccinationDay vDay) { List<Children> listChildren = childrenDaoExt.findByCommuneAndFinishedAndLocked(vDay.getCommune(), false, false);//from w ww. ja v a2 s . c o m log.debug("List update: " + listChildren.size()); if (listChildren == null || listChildren.size() == 0) return; for (Children c : listChildren) { List<ChildrenVaccinationHistory> listVaccinationPending = childrenVaccinationHistoryDaoExt .findByChildAndVaccinatedAndOderbyVaccinationId(c, (short) 0, true); List<ChildrenVaccinationHistory> listFinishedVaccinations = childrenVaccinationHistoryDaoExt .findByChildAndVaccinatedAndOderbyVaccinationId(c, (short) 1, true); Date prevDueDate = null; log.debug("************Done: " + listFinishedVaccinations.size() + " Pending: " + listVaccinationPending.size()); if (listFinishedVaccinations != null && listFinishedVaccinations.size() > 0) { prevDueDate = listFinishedVaccinations.get(listFinishedVaccinations.size() - 1) .getDateOfImmunization(); } log.debug("************DIM: " + vDay.getDateInMonth()); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String strDueDate = ""; Date dueDate = null; Integer dateInMonth = vDay.getDateInMonth(); Date today = new Date(); Integer currentMonth = today.getMonth() + 1; Integer currentYear = today.getYear() + 1900; for (int i = 0; i < listVaccinationPending.size(); i++) { ChildrenVaccinationHistory vaccinationHistory = listVaccinationPending.get(i); Vaccination vaccination = vaccinationHistory.getVaccination(); if (vaccination.getId() > 1) { Calendar recommendedTime = Calendar.getInstance(); recommendedTime.setTime(c.getDateOfBirth()); Integer deltaDate = vaccination.getAgeUnit() == 0 ? 0 : vaccination.getAge() * 30; recommendedTime.add(Calendar.DATE, deltaDate); Integer deltaYear = 0; Integer dueMonth = 0; Integer dueYear = 0; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; try { boolean overCall = false; if (vaccination.getLimitDays() != null && vaccination.getLimitDays() > 0) { Calendar c2 = Calendar.getInstance(); c2.setTime(c.getDateOfBirth()); c2.add(Calendar.DATE, vaccination.getLimitDays()); if (c2.getTime().getTime() < today.getTime()) { vaccinationHistory.setVaccinated((short) 3); vaccinationHistory.setDateOfImmunization(recommendedTime.getTime()); overCall = true; } } if (!overCall) { if (prevDueDate == null) { if (recommendedTime.getTime().getTime() >= today.getTime()) { if (recommendedTime.getTime().getYear() == today.getYear()) { if (recommendedTime.getTime().getMonth() == today.getMonth()) { if (dateInMonth >= recommendedTime.getTime().getDate()) { dueYear = recommendedTime.getTime().getYear() + 1900; dueMonth = recommendedTime.getTime().getMonth() + 1; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } else { dueMonth = recommendedTime.getTime().getMonth() + 1 + 1; deltaYear = dueMonth / 12; dueMonth = dueMonth % 12; dueYear = currentYear + deltaYear; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } } else { if (dateInMonth >= recommendedTime.getTime().getDate()) { dueYear = recommendedTime.getTime().getYear() + 1900; dueMonth = recommendedTime.getTime().getMonth() + 1; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } else { dueMonth = recommendedTime.getTime().getMonth() + 1 + 1; deltaYear = dueMonth / 12; dueMonth = dueMonth % 12; dueYear = currentYear + deltaYear; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } } } else { if (dateInMonth >= recommendedTime.getTime().getDate()) { dueYear = recommendedTime.getTime().getYear() + 1900; dueMonth = recommendedTime.getTime().getMonth() + 1; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } else { dueMonth = recommendedTime.getTime().getMonth() + 1 + 1; deltaYear = dueMonth / 12; dueMonth = dueMonth % 12; dueYear = recommendedTime.getTime().getYear() + 1900 + deltaYear; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } } dueDate = format.parse(strDueDate); vaccinationHistory.setDateOfImmunization(dueDate); } else { if (dateInMonth >= today.getDate()) { dueYear = currentYear; dueMonth = currentMonth; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } else { dueMonth = currentMonth + 1; deltaYear = dueMonth / 12; dueMonth = dueMonth % 12; dueYear = currentYear + deltaYear; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } dueDate = format.parse(strDueDate); vaccinationHistory.setDateOfImmunization(dueDate); } prevDueDate = dueDate; } else { Calendar gapTime = Calendar.getInstance(); gapTime.setTime(prevDueDate); Integer deltaGapDate = vaccination.getGap() > 0 ? vaccination.getGap() : 0; gapTime.add(Calendar.DATE, deltaGapDate); if (recommendedTime.getTime().getTime() < gapTime.getTime().getTime()) { recommendedTime = gapTime; } if (recommendedTime.getTime().getTime() >= today.getTime()) { if (recommendedTime.getTime().getYear() == today.getYear()) { if (recommendedTime.getTime().getMonth() == today.getMonth()) { if (dateInMonth >= recommendedTime.getTime().getDate()) { dueYear = recommendedTime.getTime().getYear() + 1900; dueMonth = recommendedTime.getTime().getMonth() + 1; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } else { dueMonth = recommendedTime.getTime().getMonth() + 1 + 1; deltaYear = dueMonth / 12; dueMonth = dueMonth % 12; dueYear = currentYear + deltaYear; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } } else { if (dateInMonth >= recommendedTime.getTime().getDate()) { dueYear = recommendedTime.getTime().getYear() + 1900; dueMonth = recommendedTime.getTime().getMonth() + 1; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } else { dueMonth = recommendedTime.getTime().getMonth() + 1 + 1; deltaYear = dueMonth / 12; dueMonth = dueMonth % 12; dueYear = currentYear + deltaYear; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } } } else { if (dateInMonth >= recommendedTime.getTime().getDate()) { dueYear = recommendedTime.getTime().getYear() + 1900; dueMonth = recommendedTime.getTime().getMonth() + 1; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } else { dueMonth = recommendedTime.getTime().getMonth() + 1 + 1; deltaYear = dueMonth / 12; dueMonth = dueMonth % 12; dueYear = recommendedTime.getTime().getYear() + 1900 + deltaYear; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } } dueDate = format.parse(strDueDate); vaccinationHistory.setDateOfImmunization(dueDate); } else { if (dateInMonth >= today.getDate()) { dueYear = currentYear; dueMonth = currentMonth; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } else { dueMonth = currentMonth + 1; deltaYear = dueMonth / 12; dueMonth = dueMonth % 12; dueYear = currentYear + deltaYear; strDueDate = dueYear + "-" + dueMonth + "-" + dateInMonth; } dueDate = format.parse(strDueDate); vaccinationHistory.setDateOfImmunization(dueDate); } prevDueDate = dueDate; } } childrenVaccinationHistoryDao.save(vaccinationHistory); } catch (ParseException e) { e.printStackTrace(); } } } } }
From source file:org.kuali.kpme.core.workarea.validation.WorkAreaMaintenanceDocumentRule.java
protected boolean validateRoleMembers(WorkAreaBo wa, List<? extends PrincipalRoleMemberBo> principalRoleMembers, List<? extends PositionRoleMemberBo> positionRoleMembers, LocalDate effectiveDate, String principalPrefix, String positionPrefix) { boolean valid = true; boolean activeRoleMember = false; Date efftDt = wa.getEffectiveDate(); Timestamp efftTs = new Timestamp(efftDt.getYear(), efftDt.getMonth(), efftDt.getDate(), 0, 0, 0, 0); for (ListIterator<? extends KPMERoleMemberBo> iterator = principalRoleMembers.listIterator(); iterator .hasNext();) {// ww w . ja va2 s . c o m int index = iterator.nextIndex(); KPMERoleMemberBo roleMember = iterator.next(); activeRoleMember |= roleMember.isActive(efftTs); } for (ListIterator<? extends KPMERoleMemberBo> iterator = positionRoleMembers.listIterator(); iterator .hasNext();) { int index = iterator.nextIndex(); KPMERoleMemberBo roleMember = iterator.next(); activeRoleMember |= roleMember.isActive(efftTs); valid &= validateRoleMember(roleMember, effectiveDate, positionPrefix, index); } if (!activeRoleMember) { this.putGlobalError("role.required"); valid = false; } return valid; }
From source file:at.flack.MailMainActivity.java
public String getDate(Date date) { Date today = new Date(System.currentTimeMillis()); if (date.getDate() == today.getDate() && date.getMonth() == today.getMonth() && date.getYear() == today.getYear()) return new SimpleDateFormat("HH:mm", Locale.getDefault()).format(date); else//from w w w . ja va 2s . c o m return new SimpleDateFormat("dd. MMM", Locale.getDefault()).format(date); }
From source file:com.eastcom.hrmis.modules.emp.dao.impl.EmployeeDaoImpl.java
@SuppressWarnings("deprecation") @Override// www . j av a 2s . co m public Map<String, Object> getEmployeeStatByDeptIdAndDate(String deptId, Date date) { Map<String, Object> map = Maps.newHashMap(); map.put("statDate", DateUtils.formatDate(date, "yyyy-MM")); date.setDate(1); String startDate = DateUtils.formatDate(date); date.setMonth(date.getMonth() + 1); String endDate = DateUtils.formatDate(date); Object[] params = new Object[] { startDate, endDate }; String deptSql = ""; if (StringUtils.isNotBlank(deptId)) { deptSql = " and EMPLOYEE_DEPT_ID = ? "; params = new Object[] { deptId, startDate, endDate }; } //? String enrtyCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0 " + deptSql + " ) t where t.enrty_date >= ? and t.enrty_date < ? "; // String regularCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0 and IS_REGULAR = 1" + deptSql + " ) t where t.regular_date >= ? and t.regular_date < ? "; //? String quitCompanyCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 1" + deptSql + " ) t where t.quit_company_date >= ? and t.quit_company_date < ? "; //?? String contractEndCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0" + deptSql + " ) t where t.contract_end_date >= ? and t.contract_end_date < ? "; //?? String insureCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0" + deptSql + " ) t where t.enrty_date >= ? and t.enrty_date < ? and HAS_PERSION_INSURE = 1 "; //?? String noInsureCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0" + deptSql + " ) t where t.enrty_date >= ? and t.enrty_date < ? and HAS_PERSION_INSURE = 0 "; // String retireCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0" + deptSql + " ) t where t.retire_date >= ? and t.retire_date < ? "; map.put("enrtyCount", ((BigInteger) createSqlQuery(enrtyCountSql, params).uniqueResult()).intValue()); map.put("regularCount", ((BigInteger) createSqlQuery(regularCountSql, params).uniqueResult()).intValue()); map.put("quitCompanyCount", ((BigInteger) createSqlQuery(quitCompanyCountSql, params).uniqueResult()).intValue()); map.put("contractEndCount", ((BigInteger) createSqlQuery(contractEndCountSql, params).uniqueResult()).intValue()); map.put("insureCount", ((BigInteger) createSqlQuery(insureCountSql, params).uniqueResult()).intValue()); map.put("noInsureCount", ((BigInteger) createSqlQuery(noInsureCountSql, params).uniqueResult()).intValue()); map.put("retireCount", ((BigInteger) createSqlQuery(retireCountSql, params).uniqueResult()).intValue()); return map; }
From source file:org.yccheok.jstock.gui.news.StockNewsJFrame.java
private boolean isSameDay(Date date0, Date date1) { return date0.getDate() == date1.getDate() && date0.getMonth() == date1.getMonth() && date0.getYear() == date1.getYear(); }
From source file:team.curise.controller.mana.service.EngageService.java
public void sortRoomMonthRevenue(List<RoomMonthRevenue> list) { Collections.sort(list, new Comparator<RoomMonthRevenue>() { @Override/*from w w w .ja v a 2s . com*/ public int compare(RoomMonthRevenue o1, RoomMonthRevenue o2) { if (o1 != null && o2 != null) { try { Date date1 = DateUtil.stringToDate(o1.getDate()); Date date2 = DateUtil.stringToDate(o2.getDate()); int month1 = date1.getMonth(); int month2 = date2.getMonth(); Calendar c = Calendar.getInstance(); c.setTime(date1); int year1 = c.get(Calendar.YEAR); c.setTime(date2); int year2 = c.get(Calendar.YEAR); if (year1 > year2) { return 1; } else if (year1 == year2) { if (month1 > month2) { return 1; } else if (month1 < month2) { return -1; } return 0; } } catch (ParseException ex) { Logger.getLogger(EngageService.class.getName()).log(Level.SEVERE, null, ex); } } return -1; } }); }