List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:gov.utah.dts.det.ccl.actions.facility.information.license.LicensesAction.java
@Validations(visitorFields = { @VisitorFieldValidator(fieldName = "license", message = "‌") }) @Action(value = "save-license") public String doSave() { try {/*from ww w . ja v a 2 s. c om*/ // Redmine 29236 - set previous license number status to to inactive if (license.getPreviousLicenseNumber() != null) { License previousLicense = getFacility().getLicense(license.getPreviousLicenseNumber()); previousLicense.setStatus(getInActiveType()); facilityService.saveLicense(getFacility(), license); } // When creating a new license, set the license status to In Process if it hasn't been set by the user if (license.getId() == null && license.getStatus() == null) { license.setStatus(getInProcessType()); } // set to last day of month always for expiration date - Redmine 20472 if (license.getExpirationDate() != null) { Calendar temp = Calendar.getInstance(); temp.setTime(license.getExpirationDate()); int maxDay = temp.getActualMaximum(Calendar.DAY_OF_MONTH); temp.set(Calendar.DAY_OF_MONTH, maxDay); license.setExpirationDate(temp.getTime()); } // RM #25698 // Make sure adult and youth capacity counts are set appropriately based on age group if (applicationService.propertyContainsPickListValue(license.getAgeGroup(), ApplicationPropertyKey.ADULT_YOUTH_LICENSE_AGEGROUP.getKey())) { // Adult & Youth license.setAdultMaleCount(null); license.setAdultFemaleCount(null); license.setYouthTotalSlots(null); license.setYouthMaleCount(null); license.setYouthFemaleCount(null); } else if (applicationService.propertyContainsPickListValue(license.getAgeGroup(), ApplicationPropertyKey.ADULT_LICENSE_AGEGROUP.getKey())) { // Adult license.setYouthTotalSlots(null); license.setYouthMaleCount(null); license.setYouthFemaleCount(null); } else if (applicationService.propertyContainsPickListValue(license.getAgeGroup(), ApplicationPropertyKey.YOUTH_LICENSE_AGEGROUP.getKey())) { // Youth license.setAdultTotalSlots(null); license.setAdultMaleCount(null); license.setAdultFemaleCount(null); } // Redmine 29237 // Check if license is closed and is the only active license, inactivate the facility. if (applicationService.propertyContainsPickListValue(license.getStatus(), ApplicationPropertyKey.CLOSED_LICENSE_STATUS.getKey())) { if (getIsActiveLicenseOnly().booleanValue()) { getFacility().setStatus(FacilityStatus.INACTIVE); } } // Check to see whether facility should be activated when license is activated if (applicationService.propertyContainsPickListValue(license.getStatus(), ApplicationPropertyKey.ACTIVE_LICENSE_STATUS.getKey()) && (getFacility().getStatus() == null || !getFacility().getStatus().equals(FacilityStatus.REGULATED))) { Facility fac = getFacility(); facilityService.saveLicenseWithFacilityActivation(fac, license); facilityService.evict(license); facilityService.evict(fac); } else { facilityService.saveLicense(getFacility(), license); facilityService.evict(license); } } catch (CclServiceException cse) { ViewUtils.addActionErrors(this, this, cse.getErrors()); return INPUT; } catch (Exception e) { log.error(e, e); //throw new Exception(e.getMessage(),e); } return REDIRECT_LIST; }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static Date getLatestDate() { Calendar cal = getCalendarInstance(TimeZone.getTimeZone("GMT"), Locale.getDefault()); cal.set(Calendar.YEAR, cal.getActualMaximum(Calendar.YEAR)); cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 999); return cal.getTime(); }
From source file:de.inren.service.car.CarLogEntryServiceImpl.java
@Override public List<CarLogEntry> loadLogEntriesForCarAndMonth(Long id, Date date) { // TODO use Specification List<CarLogEntry> result = new ArrayList<>(); List<CarLogEntry> all = loadLogEntriesForCar(id); LocalDateTime jodaDate = LocalDateTime.fromDateFields(date); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w w w . ja va 2 s.com*/ calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); setTimeToBeginningOfDay(calendar); final Date begining = calendar.getTime(); calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); setTimeToEndofDay(calendar); final Date end = calendar.getTime(); for (CarLogEntry entry : all) { if (entry.getPitStopDate().after(begining) && entry.getPitStopDate().before(end)) { result.add(entry); } } return result; }
From source file:com.lohika.alp.reporter.fe.dao.TestDAOImpl.java
private DetachedCriteria getFilteredCriteria(TestFilter filter) { DetachedCriteria criteria = DetachedCriteria.forClass(Test.class); criteria.createAlias("suite", "suite"); if (filter.getFrom() != null && filter.getTill() != null) { Calendar c = Calendar.getInstance(); c.setTime(filter.getFrom());//from ww w . j av a 2 s . c o m c.set(Calendar.HOUR_OF_DAY, c.getActualMinimum(Calendar.HOUR_OF_DAY)); c.set(Calendar.MINUTE, c.getActualMinimum(Calendar.MINUTE)); c.set(Calendar.SECOND, c.getActualMinimum(Calendar.SECOND)); c.set(Calendar.MILLISECOND, c.getActualMinimum(Calendar.MILLISECOND)); Date from = c.getTime(); c.setTime(filter.getTill()); c.set(Calendar.HOUR_OF_DAY, c.getActualMaximum(Calendar.HOUR_OF_DAY)); c.set(Calendar.MINUTE, c.getActualMaximum(Calendar.MINUTE)); c.set(Calendar.SECOND, c.getActualMaximum(Calendar.SECOND)); c.set(Calendar.MILLISECOND, c.getActualMaximum(Calendar.MILLISECOND)); Date till = c.getTime(); criteria.add(Restrictions.between("startDate", from, till)); } if (filter.getTest() != "" && filter.getTest() != null) { try { criteria.add(querytr.translate("name", filter.getTest())); } catch (QueryTranslatorException e) { // TODO Put QueryTranslatorException into log e.printStackTrace(); } } if (filter.getSuite() != "" && filter.getSuite() != null) { try { criteria.add(querytr.translate("suite.name", filter.getSuite())); } catch (QueryTranslatorException e) { // TODO Put QueryTranslatorException into log e.printStackTrace(); } } return criteria; }
From source file:com.sammyun.controller.console.StaticController.java
/** * ???/*from w ww. jav a 2s. c o m*/ */ @RequestMapping(value = "/build", method = RequestMethod.POST) public @ResponseBody Map<String, Object> build(BuildType buildType, Long articleCategoryId, Long productCategoryId, Date beginDate, Date endDate, Integer first, Integer count, String lang, HttpServletRequest request, HttpServletResponse response) { long startTime = System.currentTimeMillis(); if (beginDate != null) { Calendar calendar = DateUtils.toCalendar(beginDate); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); beginDate = calendar.getTime(); } if (endDate != null) { Calendar calendar = DateUtils.toCalendar(endDate); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); endDate = calendar.getTime(); } if (first == null || first < 0) { first = 0; } if (count == null || count <= 0) { count = 50; } int buildCount = 0; boolean isCompleted = true; if (lang == null) { lang = "zh_CN"; } staticService.setLocale(lang); WebUtils.removeCookie(request, response, langCookieName); WebUtils.addCookie(request, response, langCookieName, lang); if (buildType == BuildType.index) { buildCount = staticService.buildIndex(); } else if (buildType == BuildType.article) { } else if (buildType == BuildType.other) { buildCount = staticService.buildOther(); } long endTime = System.currentTimeMillis(); Map<String, Object> map = new HashMap<String, Object>(); map.put("first", first); map.put("buildCount", buildCount); map.put("buildTime", endTime - startTime); map.put("isCompleted", isCompleted); return map; }
From source file:nl.nn.ibistesttool.tibet2.Storage.java
private void addTimestampExpression(StringBuilder query, List<Object> args, String column, String operator, String searchValue, SimpleDateFormat simpleDateFormat) throws StorageException { String searchValueToParse;//from w ww.jav a 2 s.com if (searchValue.length() < 23) { if (">=".equals(operator)) { searchValueToParse = searchValue + "0000-00-00T00:00:00.000".substring(searchValue.length()); } else { searchValueToParse = searchValue + "9999-12-31T23:59:59.999".substring(searchValue.length()); } int year = -1; int month = -1; int dayOfMonth = -1; try { year = Integer.parseInt(searchValueToParse.substring(0, 4)); month = Integer.parseInt(searchValueToParse.substring(5, 7)) - 1; dayOfMonth = Integer.parseInt(searchValueToParse.substring(8, 10)); Integer.parseInt(searchValueToParse.substring(11, 13)); Integer.parseInt(searchValueToParse.substring(14, 16)); Integer.parseInt(searchValueToParse.substring(17, 19)); Integer.parseInt(searchValueToParse.substring(20, 23)); } catch (NumberFormatException e) { throwExceptionOnInvalidTimestamp(searchValue); } if (searchValueToParse.charAt(4) != '-' || searchValueToParse.charAt(7) != '-' || searchValueToParse.charAt(7) != '-' || searchValueToParse.charAt(10) != 'T' || searchValueToParse.charAt(13) != ':' || searchValueToParse.charAt(16) != ':' || searchValueToParse.charAt(19) != '.') { throwExceptionOnInvalidTimestamp(searchValue); } if (!">=".equals(operator)) { Calendar calendar = new GregorianCalendar(year, month, 1); int maxDayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); if (dayOfMonth > maxDayOfMonth) { searchValueToParse = searchValueToParse.substring(0, 8) + maxDayOfMonth + searchValueToParse.substring(10); } } } else { searchValueToParse = searchValue; } try { args.add(simpleDateFormat.parse(searchValueToParse)); addExpression(query, column + " " + operator + " ?"); } catch (ParseException e) { throwExceptionOnInvalidTimestamp(searchValue); } }
From source file:com.lohika.alp.reporter.fe.dao.TestMethodDAOImpl.java
private DetachedCriteria getFilteredCriteria(TestMethodFilter filter) { DetachedCriteria criteria = DetachedCriteria.forClass(TestMethod.class); criteria.createAlias("testInstance", "testInstance").createAlias("testInstance.testClass", "testClass") .createAlias("testInstance.test", "test"); if (filter.getFrom() != null && filter.getTill() != null) { Calendar c = Calendar.getInstance(); c.setTime(filter.getFrom());// www . jav a 2 s . c om c.set(Calendar.HOUR_OF_DAY, c.getActualMinimum(Calendar.HOUR_OF_DAY)); c.set(Calendar.MINUTE, c.getActualMinimum(Calendar.MINUTE)); c.set(Calendar.SECOND, c.getActualMinimum(Calendar.SECOND)); c.set(Calendar.MILLISECOND, c.getActualMinimum(Calendar.MILLISECOND)); Date from = c.getTime(); c.setTime(filter.getTill()); c.set(Calendar.HOUR_OF_DAY, c.getActualMaximum(Calendar.HOUR_OF_DAY)); c.set(Calendar.MINUTE, c.getActualMaximum(Calendar.MINUTE)); c.set(Calendar.SECOND, c.getActualMaximum(Calendar.SECOND)); c.set(Calendar.MILLISECOND, c.getActualMaximum(Calendar.MILLISECOND)); Date till = c.getTime(); criteria.add(Restrictions.between("startDate", from.getTime(), till.getTime())); } if (filter.getCl() != "" && filter.getCl() != null) { try { criteria.add(querytr.translate("testClass.name", filter.getCl())); } catch (QueryTranslatorException e) { // TODO Put QueryTranslatorException into log e.printStackTrace(); } } if (filter.getGr() != "" && filter.getGr() != null) { criteria.createAlias("groups", "groups"); try { criteria.add(querytr.translate("groups.name", filter.getGr())); } catch (QueryTranslatorException e) { // TODO Put QueryTranslatorException into log e.printStackTrace(); } } return criteria; }
From source file:br.ufg.calendario.components.HomeBean.java
public void setMesListener(ActionEvent event) throws ParseException { try {/*from www. ja v a2s. c om*/ int mes = Integer.parseInt((String) event.getComponent().getAttributes().get("mes")); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, calendario.getAno()); calendar.set(Calendar.MONTH, mes - 1); int diaInicio = calendar.getActualMinimum(Calendar.DAY_OF_MONTH); int diaTermino = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-M-d"); Date dataInicio = dateFormatter .parse(String.format("%04d-%02d-%02d", calendario.getAno(), mes, diaInicio)); Date dataTermino = dateFormatter .parse(String.format("%04d-%02d-%02d", calendario.getAno(), mes, diaTermino)); setBuscaDataInicio(dataInicio); setBuscaDataTermino(dataTermino); System.out.format("%02d/%02d/%04d - %02d/%02d/%04d\n", diaInicio, mes, calendario.getAno(), diaTermino, mes, calendario.getAno()); System.out.format("periodo: %s a %s\n", dateFormatter.format(dataInicio), dateFormatter.format(dataTermino)); } catch (Exception e) { System.out.println("error: " + e.getMessage()); } }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static Timestamp getMonthEnd(Timestamp stamp, TimeZone timeZone, Locale locale) { Calendar tempCal = toCalendar(stamp, timeZone, locale); tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.getActualMaximum(Calendar.DAY_OF_MONTH), 0, 0, 0); return getDayEnd(new Timestamp(tempCal.getTimeInMillis()), timeZone, locale); }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for checking whether the target date is the end of * month//from ww w. j a v a2 s .c om * * @param tgtDate * @return */ public static boolean isMonthEnd(Date tgtDate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(tgtDate); int currentDay = calendar.get(Calendar.DAY_OF_MONTH); int monthEnd = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); return (currentDay == monthEnd); }