List of usage examples for java.util Calendar getMaximum
public abstract int getMaximum(int field);
Calendar
instance. From source file:com.autentia.tnt.manager.holiday.UserHolidaysStateManager.java
public UserHolidaysState calcUserHolidaysState(User usuario, Date chargeYear) { UserHolidaysState uhs = new UserHolidaysState(); uhs.setUser(usuario);/*from w w w. ja va 2s . c o m*/ // WorkingAgreement attribute is an HB proxy not initialized, we need to get it from DB WorkingAgreementDAO workingAgreementDao = WorkingAgreementDAO.getDefault(); WorkingAgreement agreement = workingAgreementDao.getById(usuario.getAgreement().getId()); // and refresh the user instance agreement attribute usuario.setAgreement(agreement); uhs.setTotalYear(agreement.getHolidays()); int acceptedHolidays = 0; if (chargeYear != null) { HolidayManager fiestasManager = HolidayManager.getDefault(); // We must take in account previous year holidays and next year holidays Calendar calMin = Calendar.getInstance(); calMin.setTime(chargeYear); calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH)); calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH)); calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY)); calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE)); calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND)); calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND)); Calendar calMax = Calendar.getInstance(); calMax.setTime(chargeYear); calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH)); calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH)); calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY)); calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE)); calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND)); calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND)); calMin.add(Calendar.YEAR, -1); calMax.add(Calendar.YEAR, 1); HolidaySearch fiestaSearch = new HolidaySearch(); fiestaSearch.setStartDate(calMin.getTime()); fiestaSearch.setEndDate(calMax.getTime()); List<Holiday> listFiestas = fiestasManager.getAllEntities(fiestaSearch, null); calMin.setTime(chargeYear); calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH)); calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH)); calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY)); calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE)); calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND)); calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND)); calMax.setTime(chargeYear); calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH)); calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH)); calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY)); calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE)); calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND)); calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND)); RequestHolidayManager holyManager = RequestHolidayManager.getDefault(); RequestHolidaySearch holSearch = new RequestHolidaySearch(); holSearch.setUserRequest(uhs.getUser()); holSearch.setState(HolidayState.ACCEPT); holSearch.setStartChargeYear(calMin.getTime()); holSearch.setEndChargeYear(calMax.getTime()); List<RequestHoliday> listH = holyManager.getAllEntities(holSearch, null); for (RequestHoliday rH : listH) { Calendar cActual = Calendar.getInstance(); cActual.setTime(rH.getBeginDate()); while (!cActual.getTime().after(rH.getFinalDate())) { if (cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { boolean isFiesta = false; for (Holiday fiest : listFiestas) { Calendar cFiesta = Calendar.getInstance(); cFiesta.setTime(fiest.getDate()); if (cFiesta.get(Calendar.YEAR) == cActual.get(Calendar.YEAR) && cFiesta.get(Calendar.MONTH) == cActual.get(Calendar.MONTH) && cFiesta.get(Calendar.DAY_OF_MONTH) == cActual.get(Calendar.DAY_OF_MONTH)) { isFiesta = true; } } if (!isFiesta) { acceptedHolidays++; } } cActual.add(Calendar.DAY_OF_MONTH, 1); } } uhs.setTotalAccepted(acceptedHolidays); Calendar calAuxCont = Calendar.getInstance(); calAuxCont.setTime(uhs.getUser().getStartDate()); Calendar calAux = Calendar.getInstance(); calAux.setTime(chargeYear); int yearCharge = calAux.get(Calendar.YEAR); int yearContract = calAuxCont.get(Calendar.YEAR); if (yearCharge == yearContract) { // Dividimos los das de cada usuario entre los meses del ao. double ratio = uhs.getUser().getAgreement().getHolidays() / 12.0; int monthContract = calAuxCont.get(Calendar.MONTH); int meses = (Calendar.DECEMBER - monthContract); double diasVacaciones = meses * ratio; double aux = Math.ceil(diasVacaciones); uhs.setTotalYear((int) aux); } } return uhs; }
From source file:it.scoppelletti.mobilepower.types.SimpleDate.java
/** * Costruttore.//from w w w .j a va 2 s . c o m * * @param year Anno. * @param month Mese. * @param day Giorno. */ public SimpleDate(int year, int month, int day) { int min, max; Calendar cal = Calendar.getInstance(); min = cal.getMinimum(Calendar.YEAR); max = cal.getMaximum(Calendar.YEAR); if (year < min || year > max) { throw new IllegalArgumentException( String.format("Argument year %1$d is ouf of range [%2$d, %3$d].", year, min, max)); } cal.set(Calendar.YEAR, year); min = cal.getActualMinimum(Calendar.MONTH); max = cal.getActualMaximum(Calendar.MONTH); if (month < min || month > max) { throw new IllegalArgumentException( String.format("Argument month %1$d is ouf of range [%2$d, %3$d].", month, min, max)); } cal.set(Calendar.MONTH, month); min = cal.getActualMinimum(Calendar.DAY_OF_MONTH); max = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (day < min || day > max) { throw new IllegalArgumentException( String.format("Argument day %1$d is ouf of range [%2$d, %3$d].", day, min, max)); } myYear = year; myMonth = month; myDay = day; }
From source file:com.autentia.intra.bean.holiday.HolidayBean.java
/** * List holidays. Order depends on Faces parameter sort. * * @return the list of all holidays sorted by requested criterion *///from w w w . j a v a 2 s . c o m public List<Holiday> getAll() { if (selectedYear != null) { Calendar calMin = Calendar.getInstance(); calMin.setTime(selectedYear); calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH)); calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH)); calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY)); calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE)); calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND)); calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND)); Calendar calMax = Calendar.getInstance(); calMax.setTime(selectedYear); calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH)); calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH)); calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY)); calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE)); calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND)); calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND)); setSearchStartDate(calMin.getTime()); setSearchStartDateValid(true); setSearchEndDate(calMax.getTime()); setSearchEndDateValid(true); } return manager.getAllEntities(search, new SortCriteria(sortColumn, sortAscending)); }
From source file:com.autentia.intra.bean.activity.GlobalHoursReportBean.java
public float getTotalHours() { ActivitySearch search = new ActivitySearch(); Calendar init = Calendar.getInstance(); init.setTime(startDate);/*from w w w.j av a 2s . c o m*/ Calendar last = Calendar.getInstance(); last.setTime(endDate); init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY)); init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE)); init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND)); init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND)); last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY)); last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE)); last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND)); last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND)); search.setStartStartDate(init.getTime()); search.setEndStartDate(last.getTime()); if (billable) search.setBillable(true); // Search activities during indicated dates List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name")); // Search for projects in activities and create the global list. float totalHours = 0.0f; for (Activity act : activities) { float horas = act.getDuration() / 60.0f; totalHours = totalHours + horas; } return totalHours; }
From source file:com.autentia.intra.bean.activity.GlobalHoursReportBean.java
public float getNextUserTotal() { ActivitySearch search = new ActivitySearch(); Calendar init = Calendar.getInstance(); init.setTime(startDate);//from ww w . j ava 2s .c om Calendar last = Calendar.getInstance(); last.setTime(endDate); init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY)); init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE)); init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND)); init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND)); last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY)); last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE)); last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND)); last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND)); search.setStartStartDate(init.getTime()); search.setEndStartDate(last.getTime()); if (billable) search.setBillable(true); if (iterator == null) iterator = getUsers().iterator(); User user = null; try { user = iterator.next(); } catch (NoSuchElementException e) { iterator = getUsers().iterator(); user = iterator.next(); } search.setUser(user); // Search activities during indicated dates List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name")); // Search for projects in activities and create the global list. float totalHours = 0.0f; for (Activity act : activities) { float horas = act.getDuration() / 60.0f; totalHours = totalHours + horas; } return totalHours; }
From source file:com.autentia.intra.bean.activity.GlobalHoursReportBean.java
public List<GlobalHourReport> getAll() { // Retrieve activities for every User during that period of time ActivitySearch search = new ActivitySearch(); Calendar init = Calendar.getInstance(); init.setTime(startDate);/* ww w . j av a 2 s .c o m*/ Calendar last = Calendar.getInstance(); last.setTime(endDate); init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY)); init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE)); init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND)); init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND)); last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY)); last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE)); last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND)); last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND)); search.setStartStartDate(init.getTime()); search.setEndStartDate(last.getTime()); List<GlobalHourReport> listGlobal = new ArrayList<GlobalHourReport>(); if (billable) search.setBillable(true); // Search activities during indicated dates List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name")); // Search for projects in activities and create the global list. for (Activity act : activities) { Project proj = act.getRole().getProject(); GlobalHourReport unit = new GlobalHourReport(); unit.setProject(proj); // an entry in the list represents a project if (!listGlobal.contains(unit)) listGlobal.add(unit); // Retrieve the stored unit and save hours GlobalHourReport storedUnit = listGlobal.get(listGlobal.indexOf(unit)); float horas = act.getDuration() / 60.0f; storedUnit.setUserHours(act.getUser(), horas); storedUnit.setIterator(usuarios.iterator()); } return listGlobal; }
From source file:mx.edu.um.mateo.rh.dao.impl.EmpleadoDaoHibernate.java
private Criterion getQueryByMonth(Calendar gc) { Criterion cr = null;/* www . j av a 2 s . c om*/ gc.add(Calendar.YEAR, 1); gc.set(Calendar.DAY_OF_MONTH, 1); Date fechaI = gc.getTime(); gc.set(Calendar.DAY_OF_MONTH, gc.getMaximum(Calendar.DAY_OF_MONTH)); Date fechaF = gc.getTime(); cr = Restrictions.between("fechaNacimiento", fechaI, fechaF); Calendar tmp = (Calendar) gc.clone(); tmp.clear(); tmp.setTime(new Date()); tmp.add(Calendar.YEAR, -17); if (gc.compareTo(tmp) <= 0) { return Restrictions.or(cr, getQueryByMonth(gc)); } else { return cr; } }
From source file:com.autentia.tnt.bean.activity.GlobalHoursReportBean.java
public float getTotalHours() { ActivitySearch search = new ActivitySearch(); Calendar init = Calendar.getInstance(); init.setTime(startDate);//from w ww . j av a 2 s . c o m Calendar last = Calendar.getInstance(); last.setTime(endDate); init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY)); init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE)); init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND)); init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND)); last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY)); last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE)); last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND)); last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND)); search.setStartStartDate(init.getTime()); search.setEndStartDate(last.getTime()); if (billable) search.setBillable(true); // Search activities during indicated dates List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name")); // Search for projects in activities and create the global list. float totalHours = 0.0f; for (Activity act : activities) { float horas = act.getDuration() / 60.0f; totalHours = totalHours + horas; } return totalHours; }
From source file:com.autentia.tnt.bean.activity.GlobalHoursReportBean.java
public float getNextUserTotal() { ActivitySearch search = new ActivitySearch(); Calendar init = Calendar.getInstance(); init.setTime(startDate);/*ww w. j a v a 2 s.com*/ Calendar last = Calendar.getInstance(); last.setTime(endDate); init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY)); init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE)); init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND)); init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND)); last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY)); last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE)); last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND)); last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND)); search.setStartStartDate(init.getTime()); search.setEndStartDate(last.getTime()); if (billable) search.setBillable(true); if (iterator == null) iterator = getUsers().iterator(); User user = null; try { user = iterator.next(); } catch (NoSuchElementException e) { iterator = getUsers().iterator(); user = iterator.next(); } search.setUser(user); // Search activities during indicated dates List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name")); // Search for projects in activities and create the global list. float totalHours = 0.0f; for (Activity act : activities) { float horas = act.getDuration() / 60.0f; totalHours = totalHours + horas; } return totalHours; }
From source file:com.autentia.tnt.bean.activity.GlobalHoursReportBean.java
public List<GlobalHourReport> getAll() { // Retrieve activities for every User during that period of time ActivitySearch search = new ActivitySearch(); Calendar init = Calendar.getInstance(); init.setTime(startDate);/*from w ww .j ava2 s . c om*/ Calendar last = Calendar.getInstance(); last.setTime(endDate); init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY)); init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE)); init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND)); init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND)); last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY)); last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE)); last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND)); last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND)); search.setStartStartDate(init.getTime()); search.setEndStartDate(last.getTime()); List<GlobalHourReport> listGlobal = new ArrayList<GlobalHourReport>(); if (billable) search.setBillable(true); // Search activities during indicated dates List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name")); // Search for projects in activities and create the global list. for (Activity act : activities) { Project proj = act.getRole().getProject(); GlobalHourReport unit = new GlobalHourReport(); unit.setProject(proj); // an entry in the list represents a project if (!listGlobal.contains(unit)) listGlobal.add(unit); // Retrieve the stored unit and save hours GlobalHourReport storedUnit = listGlobal.get(listGlobal.indexOf(unit)); float horas = act.getDuration() / 60.0f; storedUnit.setUserHours(act.getUser(), horas); storedUnit.setIterator(usuarios.iterator()); } return listGlobal; }