List of usage examples for java.time LocalDate format
@Override
public String format(DateTimeFormatter formatter)
From source file:org.bedework.synch.cnctrs.file.FileConnectorInstance.java
@Override public URI getUri() throws SynchException { try {/* w w w . j a v a 2 s . co m*/ //Get yesterdays date final LocalDate yesterday = LocalDate.now().minus(1, ChronoUnit.DAYS); final String yesterdayStr = yesterday.format(DateTimeFormatter.ISO_LOCAL_DATE); final URI infoUri = new URI(info.getUri()); return new URIBuilder().setScheme(infoUri.getScheme()).setHost(infoUri.getHost()) .setPort(infoUri.getPort()).setPath(infoUri.getPath()).build(); } catch (final SynchException se) { throw se; } catch (final Throwable t) { throw new SynchException(t); } }
From source file:example.app.model.Person.java
protected String toString(LocalDate date) { return (date != null ? date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) : null); }
From source file:de.lgblaumeiser.ptm.rest.BookingControllerTest.java
@Test public void testRoundtripCreateAndRetrieveBooking() throws Exception { ActivityRestController.ActivityBody data = new ActivityRestController.ActivityBody(); data.activityName = "MyTestActivity"; data.bookingNumber = "0815"; mockMvc.perform(//from ww w . ja va 2s .c o m post("/activities").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(data))) .andDo(print()).andExpect(status().isCreated()); LocalDate date = LocalDate.now(); String dateString = date.format(ISO_LOCAL_DATE); BookingRestController.BookingBody booking = new BookingRestController.BookingBody(); booking.activityId = "1"; booking.user = "TestUser"; booking.starttime = LocalTime.of(8, 15).format(ISO_LOCAL_TIME); booking.comment = ""; mockMvc.perform(post("/bookings/" + dateString).contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isCreated()); mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString(dateString))); mockMvc.perform(get("/bookings/" + dateString)).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("MyTestActivity"))) .andExpect(content().string(containsString("0815"))) .andExpect(content().string(containsString("TestUser"))) .andExpect(content().string(containsString("starttime"))); mockMvc.perform(get("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("MyTestActivity"))) .andExpect(content().string(containsString("0815"))) .andExpect(content().string(containsString("TestUser"))) .andExpect(content().string(containsString("starttime"))); booking.endtime = LocalTime.of(16, 30).format(ISO_LOCAL_TIME); mockMvc.perform(post("/bookings/" + dateString + "/1").contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isOk()); mockMvc.perform(get("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("MyTestActivity"))) .andExpect(content().string(containsString("0815"))) .andExpect(content().string(containsString("TestUser"))) .andExpect(content().string(containsString("starttime"))) .andExpect(content().string(containsString("endtime"))); LocalDate date2 = date.minusDays(1); String dateString2 = date2.format(ISO_LOCAL_DATE); booking = new BookingRestController.BookingBody(); booking.activityId = "1"; booking.user = "TestUser"; booking.starttime = LocalTime.of(8, 15).format(ISO_LOCAL_TIME); booking.endtime = LocalTime.of(16, 30).format(ISO_LOCAL_TIME); booking.comment = "Test Comment"; mockMvc.perform(post("/bookings/" + dateString2).contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isCreated()); mockMvc.perform(get("/bookings/" + dateString2 + "/2")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("MyTestActivity"))) .andExpect(content().string(containsString("0815"))) .andExpect(content().string(containsString("TestUser"))) .andExpect(content().string(containsString("Test Comment"))) .andExpect(content().string(containsString("starttime"))) .andExpect(content().string(containsString("endtime"))); mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString(dateString))) .andExpect(content().string(containsString(dateString2))); mockMvc.perform(delete("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk()); mockMvc.perform(delete("/bookings/" + dateString2 + "/2")).andDo(print()).andExpect(status().isOk()); mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("[]"))); }
From source file:svc.data.citations.datasources.tyler.TylerCitationDataSource.java
@Override public List<Citation> getByNameAndMunicipalitiesAndDOB(String lastName, List<Long> municipalities, LocalDate dob) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(tylerConfiguration.rootUrl) .queryParam("lastName", lastName).queryParam("dob", dob.format(dobFormatter)); return performRestTemplateCall(builder.build().encode().toUri()); }
From source file:svc.data.citations.datasources.tyler.TylerCitationDataSource.java
@Override public List<Citation> getByCitationNumberAndDOB(String citationNumber, LocalDate dob) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(tylerConfiguration.rootUrl) .queryParam("citationNumber", citationNumber).queryParam("dob", dob.format(dobFormatter)); return performRestTemplateCall(builder.build().encode().toUri()); }
From source file:svc.data.citations.datasources.tyler.TylerCitationDataSource.java
@Override public List<Citation> getByLicenseAndDOB(String driversLicenseNumber, String driversLicenseState, LocalDate dob) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(tylerConfiguration.rootUrl) .queryParam("licenseNumber", driversLicenseNumber).queryParam("dob", dob.format(dobFormatter)) .queryParam("licenseState", driversLicenseState); return performRestTemplateCall(builder.build().encode().toUri()); }
From source file:org.bedework.synch.cnctrs.orgSyncV2.OrgSyncV2ConnectorInstance.java
@Override public URI getUri() throws SynchException { try {//from w ww. j a v a 2 s.c o m //Get yesterdays date final LocalDate yesterday = LocalDate.now().minus(1, ChronoUnit.DAYS); final String yesterdayStr = yesterday.format(DateTimeFormatter.ISO_LOCAL_DATE); final URI infoUri = new URI(info.getUri()); return new URIBuilder().setScheme(infoUri.getScheme()).setHost(infoUri.getHost()) .setPort(infoUri.getPort()).setPath(infoUri.getPath()) .setParameter("key", cnctr.getSyncher().decrypt(info.getPassword())) .setParameter("start_date", yesterdayStr).build(); } catch (final SynchException se) { throw se; } catch (final Throwable t) { throw new SynchException(t); } }
From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java
@Override public Collection<Collection<Object>> analyze(final Collection<String> parameter) { YearMonth requestedMonth = YearMonth.now(); if (parameter.size() > 0) { requestedMonth = YearMonth.parse(Iterables.get(parameter, 0)); }/*from w ww . ja v a 2 s .c o m*/ Collection<Collection<Object>> result = Lists.newArrayList(); result.add(Arrays.asList("Work Day", "Starttime", "Endtime", "Presence", "Worktime", "Breaktime", "Overtime", "Comment")); Duration overtime = Duration.ZERO; LocalDate currentday = requestedMonth.atDay(1); while (!currentday.isAfter(requestedMonth.atEndOfMonth())) { Collection<Booking> currentBookings = getBookingsForDay(currentday); if (hasCompleteBookings(currentBookings)) { String day = currentday.format(DateTimeFormatter.ISO_LOCAL_DATE); LocalTime starttime = Iterables.getFirst(currentBookings, null).getStarttime(); LocalTime endtime = Iterables.getLast(currentBookings).getEndtime(); Duration presence = calculatePresence(starttime, endtime); Duration worktime = calculateWorktime(currentBookings); Duration breaktime = calculateBreaktime(presence, worktime); Duration currentOvertime = calculateOvertime(worktime, currentday); overtime = overtime.plus(currentOvertime); result.add(Arrays.asList(day, starttime.format(DateTimeFormatter.ofPattern("HH:mm")), endtime.format(DateTimeFormatter.ofPattern("HH:mm")), formatDuration(presence), formatDuration(worktime), formatDuration(breaktime), formatDuration(overtime), validate(worktime, breaktime))); } currentday = currentday.plusDays(1); } return result; }
From source file:org.wallride.job.UpdatePostViewsItemReader.java
@Override protected void doReadPage() { if (results == null) { results = new CopyOnWriteArrayList<>(); } else {/*from www. j a v a 2s.c o m*/ results.clear(); } Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); GoogleAnalytics googleAnalytics = blog.getGoogleAnalytics(); if (googleAnalytics == null) { logger.warn("Configuration of Google Analytics can not be found"); return; } Analytics analytics = GoogleAnalyticsUtils.buildClient(googleAnalytics); try { LocalDate now = LocalDate.now(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); Analytics.Data.Ga.Get request = analytics.data().ga() .get(googleAnalytics.getProfileId(), now.minusYears(1).format(dateTimeFormatter), now.format(dateTimeFormatter), "ga:pageViews") // .setDimensions(String.format("ga:dimension%d", googleAnalytics.getCustomDimensionIndex())) // .setSort(String.format("-ga:dimension%d", googleAnalytics.getCustomDimensionIndex())) .setDimensions(String.format("ga:pagePath", googleAnalytics.getCustomDimensionIndex())) .setSort(String.format("-ga:pageViews", googleAnalytics.getCustomDimensionIndex())) .setStartIndex(getPage() * getPageSize() + 1).setMaxResults(getPageSize()); logger.info(request.toString()); final GaData gaData = request.execute(); if (CollectionUtils.isEmpty(gaData.getRows())) { return; } results.addAll(gaData.getRows()); } catch (IOException e) { logger.warn("Failed to synchronize with Google Analytics", e); throw new GoogleAnalyticsException(e); } // logger.info("Synchronization to google analytics is now COMPLETE. {} posts updated.", count); }
From source file:com.actelion.research.spiritcore.services.SampleListValidator.java
private boolean checkDateFormat(String[][] data, int col) throws Exception { DateTimeFormatter dtf = dtfBuilder.toFormatter(); DateTimeFormatter outDateFormatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy"); for (int i = 1; i < data.length; i++) { try {/*from w w w .j a v a 2s . c om*/ if (col >= data[i].length || data[i][col] == null || data[i][col].isEmpty()) { continue; } LocalDate inDate = LocalDate.parse(data[i][col], dtf); data[i][col] = inDate.format(outDateFormatter); } catch (DateTimeParseException dtpe) { specificErrorMessage = "Found value '" + data[i][col] + "' at line " + (i + 1); throw new Exception("Some dates are not in the format '" + Arrays.toString(dtPatterns) + "'.\r\n" + specificErrorMessage); } } return true; }