List of usage examples for java.util Date getYear
@Deprecated public int getYear()
From source file:graficos.GraficoGantt.java
private Date getFechaIncremento(Date fecha_com, int unidad_tiempo, int incremento) { Calendar calendario = Calendar.getInstance(); calendario.set(fecha_com.getYear() + 1900, fecha_com.getMonth(), fecha_com.getDate()); if (unidad_tiempo == Calendar.DATE) calendario.add(Calendar.DATE, incremento); else if (unidad_tiempo == Calendar.MONTH) calendario.add(Calendar.MONTH, incremento); else//from w w w .j a v a 2s.c om calendario.add(Calendar.YEAR, incremento); Date fecha = calendario.getTime(); return fecha; }
From source file:us.fatehi.creditcardnumber.ExpirationDate.java
/** * Expiration date from year and month./* w ww . ja v a 2 s .com*/ * * @param year * Year * @param month * Month */ public ExpirationDate(final Date date) { super(null); if (date != null) { expirationDate = YearMonth.of(date.getYear() + 1900, date.getMonth() + 1); } else { expirationDate = null; } }
From source file:eu.inmite.apps.smsjizdenka.util.SmsParser.java
private Date parseDate(String text, String datePattern, SimpleDateFormat sdf, SimpleDateFormat sdfTime, Ticket ticket) {//from w w w.j a v a 2s.c o m Matcher m = Pattern.compile(datePattern).matcher(text); if (m.find()) { String d = m.group(1); if (!isEmpty(d)) { d = d.replaceAll(";", ""); for (int i = 0; i < 2; i++) { final Date date; try { if (i == 0) { date = sdf.parse(d); // full date/time } else if (i == 1 && sdfTime != null) { date = sdfTime.parse(d); // only time } else { break; } } catch (Exception e) { continue; } if (i == 1 && ticket != null && ticket.validFrom != null) { final Date prevDate = ticket.validFrom; date.setYear(prevDate.getYear()); date.setMonth(prevDate.getMonth()); date.setDate(prevDate.getDate()); } return date; } } } throw new RuntimeException("Cannot parse date from the message " + text); }
From source file:kuona.jenkins.analyser.JenkinsProcessor.java
public void collectMetrics(BuildMetrics metrics) { try {//from w w w. j a va 2 s .com Utils.puts("Updating " + getURI()); final int[] jobCount = { 0 }; final int[] buildCount = { 0 }; Set<String> jobNames = getJobs().keySet(); jobCount[0] = jobNames.size(); jobNames.stream().forEach(key -> { try { JobWithDetails job = getJob(key); Utils.puts("Updating " + key); final List<Build> builds = job.details().getBuilds(); buildCount[0] += builds.size(); builds.stream().forEach(buildDetails -> { try { final BuildWithDetails details = buildDetails.details(); Timestamp timestamp = new Timestamp(details.getTimestamp()); Date buildDate = new Date(timestamp.getTime()); int year = buildDate.getYear() + 1900; if (!metrics.activity.containsKey(year)) { metrics.activity.put(year, new int[12]); } int[] yearMap = metrics.activity.get(year); yearMap[buildDate.getMonth()] += 1; if (details.getResult() == null) { metrics.buildCountsByResult.put(BuildResult.UNKNOWN, metrics.buildCountsByResult.get(BuildResult.UNKNOWN) + 1); } else { metrics.buildCountsByResult.put(details.getResult(), metrics.buildCountsByResult.get(details.getResult()) + 1); } metrics.byDuration.collect(details.getDuration()); final List<Map> actions = details.getActions(); actions.stream().filter(action -> action != null).forEach(action -> { if (action.containsKey("causes")) { List<HashMap> causes = (List<HashMap>) action.get("causes"); causes.stream().filter(cause -> cause.containsKey("shortDescription")) .forEach(cause -> { metrics.triggers.add((String) cause.get("shortDescription")); }); } }); metrics.completedBuilds.add(details); } catch (IOException e) { e.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } }); metrics.dashboardServers.add(new HashMap<String, Object>() { { MainView serverInfo = getServerInfo(); put("name", serverInfo.getName()); put("description", serverInfo.getDescription()); put("uri", getURI().toString()); put("jobs", jobCount[0]); put("builds", buildCount[0]); } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.openmrs.module.rwandaprimarycare.ExtendPatientNameSearchController.java
@RequestMapping("/module/rwandaprimarycare/extendNameSearch") public String setupForm(@RequestParam("givenName") String givenName, @RequestParam("familyName") String familyName, @RequestParam("gender") String gender, @RequestParam("age") Integer age, @RequestParam(required = false, value = "birthdateDay") Integer birthdateDay, @RequestParam(required = false, value = "birthdateMonth") Integer birthdateMonth, @RequestParam(required = false, value = "birthdateYear") Integer birthdateYear, @RequestParam("country") String country, @RequestParam("province") String province, @RequestParam("district") String district, @RequestParam("sector") String sector, @RequestParam("cell") String cell, @RequestParam("address1") String address1, HttpSession session, ModelMap model) throws PrimaryCareException { // LK: Need to ensure that all primary care methods only throw a // PrimaryCareException // So that errors will be directed to a touch screen error page GetPatientUtil getPatientUtil = new GetPatientUtil(); try {//from w w w . j a v a 2 s . co m if (givenName != null) { log.info("FANAME >> " + givenName); log.info("RWNAME >> " + familyName); model.addAttribute("givenName", givenName); TreeMap<String, String> params = new TreeMap<String, String>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); Calendar c = Calendar.getInstance(); c.add(Calendar.YEAR, -age); c.add(Calendar.DATE, -183); Date d = c.getTime(); int year = d.getYear(); String df = sdf.format(d); log.info(df + "<< >>" + year); params.put("dob", df); if (givenName != null && givenName != "") { params.put("given_name", givenName); } if (familyName != null && familyName != "") { params.put("family_name", familyName); } if (gender != null && gender != "") { params.put("gender", gender); } if (province != null && province != "") { params.put("addr_province", province); } if (district != null && district != "") { params.put("addr_district", district); } if (sector != null && sector != "") { params.put("addr_sector", sector); } if (cell != null && cell != "") { params.put("addr_cell", cell); } if (address1 != null && address1 != "") { params.put("addr_village", address1); } model.addAttribute("givenName", givenName); model.addAttribute("familyName", familyName); model.addAttribute("gender", gender); model.addAttribute("age", age); model.addAttribute("searchUMUDUGUDU", address1); model.addAttribute("searchCELL", cell); model.addAttribute("searchDISTRICT", district); model.addAttribute("searchCOUNTRY", country); model.addAttribute("searchPROVINCE", province); model.addAttribute("searchSECTOR", sector); //model.addAttribute("CR", "Client Reg"); //List<AttributeList> result = new ArrayList<AttributeList>(); // List<Patient> extendedResults = getPatientUtil // .getPatientFromClientReg(params); List<AttributeList> results = getPatientUtil.getPatientWithAttributeListFromClientReg(params); if (results.size() > 0) { for (AttributeList al : results) { String nid = ""; if (al.getPatient().getPatientIdentifier("NID") != null) { nid = al.getPatient().getPatientIdentifier("NID").getIdentifier(); al.setNid(nid); log.info("Moms name == " + al.getMothersName()); } else { nid = "Unavailable"; al.setNid(nid); } } } // if(extendedResults.size()>0){ // for(Patient p:extendedResults){ // String mothersName=""; // String fathersName=""; // String nid = ""; // if(p.getPatientIdentifier("NID")!=null){ // nid = p.getPatientIdentifier("NID").getIdentifier(); // } // else{ // nid = "Unavailable"; // } // PersonAttributeType mName = Context.getPersonService().getPersonAttributeTypeByName( // PrimaryCareConstants.MOTHER_NAME_ATTRIBUTE_TYPE) ; // PersonAttributeType fName = Context.getPersonService().getPersonAttributeTypeByName( // PrimaryCareConstants.FATHER_NAME_ATTRIBUTE_TYPE) ; // // if (p.getAttribute(mName) != null) { // mothersName = p.getAttribute(mName).getValue(); // // } // // if (p.getAttribute(fName) != null) { // fathersName = p.getAttribute(fName).getValue(); // // } // // AttributeList al = new AttributeList(p, mothersName, fathersName, nid); // results.add(al); // // } // } // model.addAttribute("results", results); model.addAttribute("identifierTypes", PrimaryCareBusinessLogic.getPatientIdentifierTypesToUse()); } } catch (Exception e) { e.printStackTrace(); throw new PrimaryCareException(e); } return "/module/rwandaprimarycare/extendedResults"; }
From source file:com.agroservices.logic.entidadBancariaFacade.java
public boolean validarTarjeta(informacionTarjeta tarjeta) { Date fecha = new Date(); boolean respuesta = true; if (tarjeta.getNumero() % 2 != 0) { System.out.println("Numero tarjeta: " + tarjeta.getNumero() + " Modulo: " + tarjeta.getNumero() % 2); respuesta = false;/*from w w w .j a v a 2 s .c o m*/ } if (tarjeta.getAnoVencimiento() < (fecha.getYear() + 1900)) { System.out.println("Ao tarjeta: " + tarjeta.getAnoVencimiento() + " Ao de la fecha: " + fecha.getYear() + 1900); respuesta = false; } if (tarjeta.getMesVencimiento() < (fecha.getMonth() + 1) && (tarjeta.getAnoVencimiento() == (fecha.getYear() + 1900))) { System.out.println("mes tarjeta: " + tarjeta.getMesVencimiento() + " Modulo: " + fecha.getMonth() + 1); respuesta = false; } return respuesta; }
From source file:kuona.processor.JenkinsProcessor.java
public void collectMetrics(BuildMetrics metrics) { try {/*from ww w . j a v a2s. co m*/ puts("Updating " + getURI()); final int[] jobCount = { 0 }; final int[] buildCount = { 0 }; Set<String> jobNames = getJobs().keySet(); jobCount[0] = jobNames.size(); jobNames.stream().forEach(key -> { try { JobWithDetails job = getJob(key); puts("Updating " + key); final List<Build> builds = job.details().getBuilds(); buildCount[0] += builds.size(); builds.stream().forEach(buildDetails -> { try { final BuildWithDetails details = buildDetails.details(); Timestamp timestamp = new Timestamp(details.getTimestamp()); Date buildDate = new Date(timestamp.getTime()); int year = buildDate.getYear() + 1900; if (!metrics.activity.containsKey(year)) { metrics.activity.put(year, new int[12]); } int[] yearMap = metrics.activity.get(year); yearMap[buildDate.getMonth()] += 1; if (details.getResult() == null) { metrics.buildCountsByResult.put(BuildResult.UNKNOWN, metrics.buildCountsByResult.get(BuildResult.UNKNOWN) + 1); } else { metrics.buildCountsByResult.put(details.getResult(), metrics.buildCountsByResult.get(details.getResult()) + 1); } metrics.byDuration.collect(details.getDuration()); final List<Map> actions = details.getActions(); actions.stream().filter(action -> action != null).forEach(action -> { if (action.containsKey("causes")) { List<HashMap> causes = (List<HashMap>) action.get("causes"); causes.stream().filter(cause -> cause.containsKey("shortDescription")) .forEach(cause -> { metrics.triggers.add((String) cause.get("shortDescription")); }); } }); metrics.completedBuilds.add(details); } catch (IOException e) { e.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } }); metrics.dashboardServers.add(new HashMap<String, Object>() { { MainView serverInfo = getServerInfo(); put("name", serverInfo.getName()); put("description", serverInfo.getDescription()); put("uri", getURI().toString()); put("jobs", jobCount[0]); put("builds", buildCount[0]); } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.org.dqgb.action.CustomerAction.java
/** * ??//w w w.ja v a 2 s . c om * @author * @date 2011-9-30 * @return String */ @SuppressWarnings("deprecation") public String getCustomerAddition() { try { int year = NumberUtils.toInt(this.getHttpServletRequest().getParameter("year")); if (year == 0) { Date date = new Date(); year = date.getYear() + 1900; } List<Map<String, String>> yearmonth = new ArrayList<Map<String, String>>(); for (int i = 1; i <= 12; i++) { Map<String, String> map = new HashMap<String, String>(); map.put("customerName", year + "/" + i); map.put("leaf", "false"); yearmonth.add(map); } output.put(Constant.DATA, yearmonth); output.put(Constant.TOTAL_SIZE, 12); } catch (Exception e) { output.put(Constant.RESULT, Constant.FAILED); output.put(Constant.REASON, e.getMessage()); } return SUCCESS; }
From source file:org.kuali.kra.service.impl.PersonEditableServiceImpl.java
public void populateContactFieldsFromPersonId(PersonEditableInterface protocolPerson) { DateFormat dateFormat = new SimpleDateFormat(Constants.DEFAULT_DATE_FORMAT_PATTERN); KcPerson person = this.kcPersonService.getKcPersonByPersonId(protocolPerson.getPersonId()); protocolPerson.setSocialSecurityNumber(person.getSocialSecurityNumber()); protocolPerson.setLastName(person.getLastName()); protocolPerson.setFirstName(person.getFirstName()); protocolPerson.setMiddleName(person.getMiddleName()); protocolPerson.setFullName(person.getFullName()); protocolPerson.setPriorName(person.getPriorName()); protocolPerson.setUserName(person.getUserName()); protocolPerson.setEmailAddress(person.getEmailAddress()); //prop_person.setDateOfBirth(person.getDateOfBirth()); try {//from w w w . j a va 2 s. c o m java.util.Date dobUtil = dateFormat.parse(person.getDateOfBirth()); protocolPerson .setDateOfBirth(new java.sql.Date(dobUtil.getYear(), dobUtil.getMonth(), dobUtil.getDate())); } catch (Exception e) { //invalid date protocolPerson.setDateOfBirth(null); } protocolPerson.setAge(person.getAge()); protocolPerson.setAgeByFiscalYear(person.getAgeByFiscalYear()); protocolPerson.setGender(person.getGender()); protocolPerson.setRace(person.getRace()); protocolPerson.setEducationLevel(person.getEducationLevel()); protocolPerson.setDegree(person.getDegree()); protocolPerson.setMajor(person.getMajor()); protocolPerson.setHandicappedFlag(person.getHandicappedFlag()); protocolPerson.setHandicapType(person.getHandicapType()); protocolPerson.setVeteranFlag(person.getVeteranFlag()); protocolPerson.setVeteranType(person.getVeteranType()); protocolPerson.setVisaCode(person.getVisaCode()); protocolPerson.setVisaType(person.getVisaType()); //prop_person.setVisaRenewalDate(person.getVisaRenewalDate()); try { java.util.Date visaUtil = dateFormat.parse(person.getVisaRenewalDate()); protocolPerson.setVisaRenewalDate( new java.sql.Date(visaUtil.getYear(), visaUtil.getMonth(), visaUtil.getDate())); } catch (Exception e) { //invalid date protocolPerson.setVisaRenewalDate(null); } protocolPerson.setHasVisa(person.getHasVisa()); protocolPerson.setOfficeLocation(person.getOfficeLocation()); protocolPerson.setOfficePhone(person.getOfficePhone()); protocolPerson.setSecondaryOfficeLocation(person.getSecondaryOfficeLocation()); protocolPerson.setSecondaryOfficePhone(person.getSecondaryOfficePhone()); protocolPerson.setSchool(person.getSchool()); protocolPerson.setYearGraduated(person.getYearGraduated()); protocolPerson.setDirectoryDepartment(person.getDirectoryDepartment()); protocolPerson.setSaluation(person.getSaluation()); protocolPerson.setCountryOfCitizenship(person.getCountryOfCitizenship()); protocolPerson.setPrimaryTitle(person.getPrimaryTitle()); protocolPerson.setDirectoryTitle(person.getDirectoryTitle()); protocolPerson.setHomeUnit(person.getOrganizationIdentifier()); protocolPerson.setFacultyFlag(person.getFacultyFlag()); protocolPerson.setGraduateStudentStaffFlag(person.getGraduateStudentStaffFlag()); protocolPerson.setResearchStaffFlag(person.getResearchStaffFlag()); protocolPerson.setServiceStaffFlag(person.getServiceStaffFlag()); protocolPerson.setSupportStaffFlag(person.getSupportStaffFlag()); protocolPerson.setOtherAcademicGroupFlag(person.getOtherAcademicGroupFlag()); protocolPerson.setMedicalStaffFlag(person.getMedicalStaffFlag()); protocolPerson.setVacationAccrualFlag(person.getVacationAccrualFlag()); protocolPerson.setOnSabbaticalFlag(person.getOnSabbaticalFlag()); protocolPerson.setIdProvided(person.getIdProvided()); protocolPerson.setIdVerified(person.getIdVerified()); protocolPerson.setAddressLine1(person.getAddressLine1()); protocolPerson.setAddressLine2(person.getAddressLine2()); protocolPerson.setAddressLine3(person.getAddressLine3()); protocolPerson.setCity(person.getCity()); protocolPerson.setCounty(person.getCounty()); protocolPerson.setState(person.getState()); protocolPerson.setPostalCode(person.getPostalCode()); protocolPerson.setCountryCode(person.getCountryCode()); protocolPerson.setFaxNumber(person.getFaxNumber()); protocolPerson.setPagerNumber(person.getPagerNumber()); protocolPerson.setMobilePhoneNumber(person.getMobilePhoneNumber()); protocolPerson.setEraCommonsUserName(person.getEraCommonsUserName()); }
From source file:com.webpagebytes.wpbsample.SampleJob.java
public void execute(JobExecutionContext context) throws JobExecutionException { log.log(Level.INFO, "Sample quartz scheduler started"); // create the email subject value Date yesterday = DateUtility.addDays(DateUtility.getToday(), -1); String subject = String.format("Sample webpagebytes application report(%d/%d/%d)", 1900 + yesterday.getYear(), yesterday.getMonth() + 1, yesterday.getDate()); // various variables used during report generation ByteArrayOutputStream bos_emailBody = new ByteArrayOutputStream(4096); ByteArrayOutputStream bos_emailAttachmentFop = new ByteArrayOutputStream(4096); InputStream is_emailAttachmentFop = null; ByteArrayOutputStream bos_emailAttachmentPdf = new ByteArrayOutputStream(4096); ByteArrayInputStream bis_emailAttachmentPdf = null; try {/*from ww w. j ava2s .c o m*/ // get the content provider instance WPBContentService contentService = WPBContentServiceFactory.getInstance(); WPBContentProvider contentProvider = contentService.getContentProvider(); // create the cmd model WPBModel model = contentService.createModel(); //get the report images for users, transactions, deposits and withdrawals // the images and stored in a map, the image content is base64 encoded Map<String, String> contentImages = new HashMap<String, String>(); NotificationUtility.fetchReportImages(contentProvider, model, contentImages); //populate the model with image values model.getCmsApplicationModel().put("users_img", contentImages.get(NotificationUtility.CONTENT_IMG_USERS)); model.getCmsApplicationModel().put("transactions_img", contentImages.get(NotificationUtility.CONTENT_IMG_TRANSACTIONS)); model.getCmsApplicationModel().put("deposits_img", contentImages.get(NotificationUtility.CONTENT_IMG_DEPOSITS)); model.getCmsApplicationModel().put("withdrawals_img", contentImages.get(NotificationUtility.CONTENT_IMG_WITHDRAWALS)); // get from the GLOBALS parameters the user who will receive the email notification String notificationEmailAddress = model.getCmsModel().get(WPBModel.GLOBALS_KEY) .get("NOTIFICATIONS_EMAIL_ADDRESS"); // get from the GLOBALS parameters the page guid with the email body template String notificationEmailPageGuid = model.getCmsModel().get(WPBModel.GLOBALS_KEY) .get("NOTIFICATIONS_EMAIL_PAGE_GUID"); // get from the GLOBALS parameters the page guid with the PDF report XSL-FO template String notificationEmailAttachmentGuid = model.getCmsModel().get(WPBModel.GLOBALS_KEY) .get("NOTIFICATIONS_EMAIL_PDF_GUID"); if (notificationEmailAddress == null || notificationEmailPageGuid == null || notificationEmailAttachmentGuid == null) { // if any of these is not set then do not sent the email log.log(Level.WARNING, "Sample scheduler not properly configured, will not send any email"); return; } // translate the email body template into the actual body content contentProvider.writePageContent(notificationEmailPageGuid, model, bos_emailBody); // translate the attachment XSL FO template into the actual XSL FO content contentProvider.writePageContent(notificationEmailAttachmentGuid, model, bos_emailAttachmentFop); // need to convert the attachment XSL FO OutputStream into InputStream is_emailAttachmentFop = new ByteArrayInputStream(bos_emailAttachmentFop.toByteArray()); SampleFopService fopService = SampleFopService.getInstance(); fopService.getContent(is_emailAttachmentFop, MimeConstants.MIME_PDF, bos_emailAttachmentPdf); //need to convert the attachment PDF OutputStream into InputStream bis_emailAttachmentPdf = new ByteArrayInputStream(bos_emailAttachmentPdf.toByteArray()); // now we have the email subject, email body, email attachment, we can sent it if (notificationEmailAddress.length() > 0) { EmailUtility emailUtility = EmailUtilityFactory.getInstance(); emailUtility.sendEmail(notificationEmailAddress, "no-reply@webpagebytes.com", subject, bos_emailBody.toString("UTF-8"), "report.pdf", bis_emailAttachmentPdf); } log.log(Level.INFO, "Sample quartz scheduler completed with success"); } catch (Exception e) { log.log(Level.SEVERE, "Exception on quartz scheduler", e); } finally { IOUtils.closeQuietly(bos_emailBody); IOUtils.closeQuietly(bos_emailAttachmentFop); IOUtils.closeQuietly(is_emailAttachmentFop); IOUtils.closeQuietly(bis_emailAttachmentPdf); IOUtils.closeQuietly(bos_emailAttachmentPdf); } }