List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:mx.clickfactura.util.TipoCambioUtil.java
public String getTipoCambio(String fecha) throws CustomBadRequestException, CustomNotFoundException, Exception { Pattern pattern = Pattern.compile("^\\d{4}\\-\\d{2}\\-\\d{2}$"); Matcher matcher = null;/*from w w w . java 2 s . c o m*/ matcher = pattern.matcher(fecha.trim()); if (!matcher.matches()) { throw new CustomBadRequestException("Fecha invalida, el formato debe ser: yyyy-MM-dd"); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = new GregorianCalendar(); cal.setTime(sdf.parse(fecha)); String dia = (cal.get(Calendar.DATE) < 10) ? "0" + cal.get(Calendar.DATE) : cal.get(Calendar.DATE) + ""; String mes = ((cal.get(Calendar.MONTH) + 1) < 10) ? "0" + (cal.get(Calendar.MONTH) + 1) : (cal.get(Calendar.MONTH) + 1) + ""; String anio = cal.get(Calendar.YEAR) + ""; String fechaInicial = dia + "%2F" + mes + "%2F" + anio; CloseableHttpClient client = HttpClients.createDefault(); CookieStore cookies = new BasicCookieStore(); String[] fechaSeparada = fecha.split("-"); HttpGet get = new HttpGet("http://www.dof.gob.mx/indicadores_detalle.php?cod_tipo_indicador=158&dfecha=" + fechaInicial + "&hfecha=" + fechaInicial); HttpContext httpContext = new BasicHttpContext(); httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookies); CloseableHttpResponse response = client.execute(get, httpContext); //System.out.println(response.toString()); //System.out.println(response.getStatusLine()); //System.out.println(response.getEntity().getContentLength()); InputStream in = response.getEntity().getContent(); Header encoding = response.getEntity().getContentEncoding(); String body = IOUtils.toString(in, "UTF-8"); //System.out.println(body); Document doc = Jsoup.parse(body, "UTF-8"); doc = doc.normalise(); //System.out.println(doc.toString()); Elements e = doc.select("table"); Iterator iterator = e.iterator(); pattern = Pattern.compile("^\\d{2}\\.\\d{6}$"); matcher = null; String tipoCambio = null; while (iterator.hasNext()) { Element xd = (Element) iterator.next(); if (xd.getElementsByClass("txt").hasAttr("height")) { if (xd.getElementsByClass("txt").text().split(" ").length == 6) { String cambio = xd.getElementsByClass("txt").text().split(" ")[5]; matcher = pattern.matcher(cambio.trim()); if (matcher.matches()) { tipoCambio = cambio; //System.out.println(tipoCambio); break; } } } } client.close(); response.close(); if (tipoCambio == null || tipoCambio.isEmpty()) { throw new CustomNotFoundException("No hay un tipo de cambio para el da: " + fecha); } return tipoCambio; }
From source file:gov.nih.nci.cabig.caaers.utils.DateUtils.java
/** * This is a convenient method to get tomorrow * @return/* w ww . j a va2 s . c o m*/ */ public static Date tomorrow() { Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, 1); Date d = c.getTime(); d.setHours(0); d.setMinutes(0); return d; }
From source file:de.tor.tribes.ui.components.DatePicker.java
public DatePicker(Date date) { initComponents();/*from ww w.java 2 s.c om*/ if (date == null) { originalDate = DateUtils.truncate(new Date(), Calendar.DATE); } else { originalDate = DateUtils.truncate(date, Calendar.DATE); } selectedDate = originalDate; init(); }
From source file:org.openmrs.module.OT.web.controller.minorOT.queue.RescheduleProcedureController.java
@RequestMapping(method = RequestMethod.GET) public String showRescheduleForm(Model model, @RequestParam(value = "type", required = false) String type, @ModelAttribute("schedule") OpdTestOrder schedule) { if (schedule != null) { OTScheduleModel otm = OperationTheatreUtil.generateRescheduleModel(schedule); model.addAttribute("procedure", otm); Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, 1); model.addAttribute("currentDate", OperationTheatreUtil.formatDate(c.getTime())); }//w w w. j a v a 2 s.c o m return "/module/OT/minorOT/rescheduleForm"; }
From source file:com.sap.csc.poc.ems.persistence.initial.entitlement.SoftwareLicenseEntitlementItemDataInitializer.java
private Validity createRandomValidity() { Validity validity = new Validity(); Calendar validityFrom = Calendar.getInstance(); validityFrom.add(Calendar.DATE, -RandomUtils.nextInt(1, 90)); validity.setValidityFrom(validityFrom); Calendar validityTo = Calendar.getInstance(); validityTo.add(Calendar.DATE, RandomUtils.nextInt(30, 360)); validity.setValidityTo(validityTo);//from w w w . j ava 2 s .c o m return validity; }
From source file:org.openmrs.module.OT.web.controller.majorOT.queue.RescheduleProcedureController.java
@RequestMapping(method = RequestMethod.GET) public String showRescheduleForm(Model model, @RequestParam(value = "type", required = false) String type, @ModelAttribute("schedule") OpdTestOrder schedule) { if (schedule != null) { OTScheduleModel otm = OperationTheatreUtil_Major.generateRescheduleModel(schedule); model.addAttribute("procedure", otm); Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, 1); model.addAttribute("currentDate", OperationTheatreUtil_Major.formatDate(c.getTime())); }/* ww w .j av a 2 s .c om*/ return "/module/OT/majorOT/rescheduleForm"; }
From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java
/** * * This method computes the number of months between any 2 given {@link java.sql.Date} objects * * @param dateStart starting date./*www.j a va2s. c o m*/ * @param dateEnd end date. * * @return number of months between the start date and end date. */ @Override public ScaleTwoDecimal getNumberOfMonths(java.util.Date dateStart, java.util.Date dateEnd) { ScaleTwoDecimal monthCount = ScaleTwoDecimal.ZERO; int fullMonthCount = 0; Calendar startDate = Calendar.getInstance(); Calendar endDate = Calendar.getInstance(); startDate.setTime(dateStart); endDate.setTime(dateEnd); startDate.clear(Calendar.HOUR); startDate.clear(Calendar.MINUTE); startDate.clear(Calendar.SECOND); startDate.clear(Calendar.MILLISECOND); endDate.clear(Calendar.HOUR); endDate.clear(Calendar.MINUTE); endDate.clear(Calendar.SECOND); endDate.clear(Calendar.MILLISECOND); if (startDate.after(endDate)) { return ScaleTwoDecimal.ZERO; } int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE); startMonthDays++; int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE); BigDecimal startMonthFraction = BigDecimal.valueOf(startMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(startMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); int endMonthDays = endDate.get(Calendar.DATE); int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE); BigDecimal endMonthFraction = BigDecimal.valueOf(endMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(endMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); startDate.set(Calendar.DATE, 1); endDate.set(Calendar.DATE, 1); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1); fullMonthCount++; } fullMonthCount = fullMonthCount - 1; monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount)) .add(new ScaleTwoDecimal(startMonthFraction)).add(new ScaleTwoDecimal(endMonthFraction)); return monthCount; }
From source file:com.cemeterylistingswebtest.test.services.AdminPublishedListingServiceTest.java
@Test public void hello() { pubRepo = ctx.getBean(PublishedDeceasedListingRepository.class); updatePubserv = ctx.getBean(AdminUpdatePublishedListingService.class); subRepo = ctx.getBean(SubscriberRepository.class); userRepo = ctx.getBean(UserRoleRepository.class); //Initialise date Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.MARCH); calendar.set(Calendar.DATE, 5); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); //Initialise date Calendar calendar2 = Calendar.getInstance(); calendar2.set(Calendar.YEAR, 2014); calendar2.set(Calendar.MONTH, Calendar.JUNE); calendar2.set(Calendar.DATE, 20); java.sql.Date validDate = new java.sql.Date(calendar2.getTime().getTime()); //Initialise user role UserRole userRole = new UserRole.Builder().setLevel(2).build(); Subscriber newSub = new Subscriber.Builder().setEmail("jackieChan@yahoo.com").setFirstName("jackie") .setSurname("Chan").setPwd("whaa").setUsername("jChan").setSubscriptionDate(javaSqlDate) .setUserRoleID(userRole).setValidUntil(validDate).build(); subRepo.save(newSub);//from w w w . j a v a2 s . com subID = newSub.getSubscriberID(); PublishedDeceasedListing newListing = new PublishedDeceasedListing.Builder().setFirstName("Dean") .setSurname("Winchester") .setGender("Male").setDateOfBirth("27/07/1985").setDateOfDeath("14/10/2014") .setGraveInscription("will probably come back").setGraveNumber("2474") .setImageOfBurialSite("/images/004.jpg").setLastKnownContactName("sam") .setLastKnownContactNumber("07255718927") .setSubscriberSubmitID(subID).build(); pubRepo.save(newListing); listingId = newListing.getPublishedListingID(); PublishedDeceasedListing updateListing = new PublishedDeceasedListing.Builder() .PublishedDeceasedListing(newListing).setFirstName("Sam").setSurname(newListing.getSurname()) .setMaidenName(newListing.getMaidenName()).setGender(newListing.getGender()) .setDateOfBirth(newListing.getDateOfBirth()).setDateOfDeath(newListing.getDateOfDeath()) .setGraveInscription(newListing.getGraveInscription()).setGraveNumber(newListing.getGraveNumber()) .setLastKnownContactName(newListing.getLastKnownContactName()) .setLastKnownContactNumber(newListing.getLastKnownContactNumber()) .setCemeteryID(newListing.getCemeteryID()) .setSubscriberApprovedID(newListing.getSubscriberApprovedID()) .setSubscriberSubmitID(newListing.getSubscriberSubmitID()).setNames(newListing.getNames()) .setSubscriberSubmitID(subID).build(); //listingId, "Sam", "Winchester", "", "Male", "20/07/1980", "14/10/2014", "Came back", "2474", "/images/004.jpg", "Dean", "07255718927", subID, null id = updatePubserv.updatePublishedlistingReturn(updateListing); PublishedDeceasedListing pubUpdate = updatePubserv.find(id); Assert.assertNotNull(updatePubserv.find(id)); Assert.assertEquals(pubUpdate.getFirstName(), "Sam"); PublishedDeceasedListing pub = pubRepo.findOne(listingId); Assert.assertNotNull(pubRepo.findOne(listingId)); Assert.assertEquals(pub.getFirstName(), "Sam"); pubRepo.delete(newListing); subRepo.delete(newSub); updatePubserv.remove(updateListing); }
From source file:com.cemeterylistingswebtest.test.services.ViewListingByDateOfDeathServiceTest.java
@Test(enabled = true) public void TestDoD() { dateServ = ctx.getBean(ViewListingByDateOfDeathService.class); repoList = ctx.getBean(PublishedDeceasedListingRepository.class); subRepo = ctx.getBean(SubscriberRepository.class); userRepo = ctx.getBean(UserRoleRepository.class); //Initialise date Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); //Initialise user role UserRole userRole = new UserRole.Builder().setLevel(1).build(); //userRepo.save(userRole); //userRoleID = userRole.getUserRoleID(); //Initialise subscriber Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com") .setFirstName("Manfred").setSurname("Osulivan").setPwd("jesus").setUsername("ManiFredOssy") .setSubscriptionDate(javaSqlDate).setUserRoleID(userRole).build(); subRepo.save(newSub);/*from w w w. j a v a2 s. c om*/ subID = newSub.getSubscriberID(); PublishedDeceasedListing newListing = new PublishedDeceasedListing.Builder().setFirstName("Hendrika") .setSurname("Fourie").setMaidenName("Gerber").setGender("Female").setDateOfBirth("08/06/1969") .setDateOfDeath("14/02/2005").setGraveInscription("Hippiest person eva").setGraveNumber("2456") .setImageOfBurialSite("/images/001.jpg").setLastKnownContactName("Berry") .setLastKnownContactNumber("0725576482") .setSubscriberSubmitID(subID).build(); repoList.save(newListing); List<PublishedDeceasedListing> pubListDod = dateServ.findListingByDOD("14/02/2005"); Assert.assertFalse(pubListDod.isEmpty()); repoList.delete(newListing); subRepo.delete(subID); }
From source file:org.ngrinder.infra.report.PeriodicCollectDataToGAService.java
/** * Send the number of executed test.//w w w.j av a 2 s .com */ @Scheduled(cron = "0 1 1 * * ?") @Transactional public void reportUsage() { if (config.isUsageReportEnabled()) { doRandomDelay(); GoogleAnalytic googleAnalytic = new GoogleAnalytic(ControllerConstants.GOOGLE_ANALYTICS_APP_NAME, config.getVersion(), ControllerConstants.GOOGLE_ANALYTICS_TRACKING_ID); MeasureProtocolRequest measureProtocolRequest = googleAnalytic.getMeasureProtocolRequest(); measureProtocolRequest.setEventCategory("usage"); measureProtocolRequest.setEventAction("executions"); String currentAddress = NetworkUtils.getLocalHostAddress(); Date yesterday = DateUtils.addDays(new Date(), -1); Date start = DateUtils.truncate(yesterday, Calendar.DATE); Date end = DateUtils.addMilliseconds(DateUtils.ceiling(yesterday, Calendar.DATE), -1); googleAnalytic.sendStaticDataToUA(currentAddress, String.valueOf(getUsage(start, end))); } }