List of usage examples for java.time.format DateTimeFormatter ofPattern
public static DateTimeFormatter ofPattern(String pattern)
From source file:fi.helsinki.opintoni.service.StudyAttainmentServiceTest.java
private void assertStudyAttainmentDto(StudyAttainmentDto studyAttainmentDto) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); assertThat(studyAttainmentDto.attainmentDate.format(formatter)).isEqualTo(ATTAINMENT_DATE); assertThat(studyAttainmentDto.credits).isEqualTo(CREDITS); assertThat(studyAttainmentDto.grade).isEqualTo(GRADE); assertThat(studyAttainmentDto.learningOpportunityName).isEqualTo(LEARNING_OPPORTINITY_NAME); assertThat(TEACHERS.stream().map(t1 -> t1.shortName).collect(Collectors.toList())).isEqualTo( studyAttainmentDto.teachers.stream().map(t2 -> t2.shortName).collect(Collectors.toList())); }
From source file:net.straylightlabs.archivo.net.MindCommandRecordingSearch.java
public Recording getRecording() { failOnInvalidState();//from w w w . j ava 2 s .c om Recording.Builder builder = new Recording.Builder(); logger.trace("Response: {}", response); if (response.has("recording")) { JSONArray recordingsJSON = response.getJSONArray("recording"); for (Object obj : recordingsJSON) { JSONObject recordingJSON = (JSONObject) obj; if (recordingJSON.has(RECORDING_ID)) builder.recordingId(recordingJSON.getString(RECORDING_ID)); if (recordingJSON.has(BODY_ID)) builder.bodyId(recordingJSON.getString(BODY_ID)); if (recordingJSON.has("title")) builder.seriesTitle(recordingJSON.getString("title")); if (recordingJSON.has("collectionType")) builder.collectionType(recordingJSON.getString("collectionType")); if (recordingJSON.has("subtitle")) builder.episodeTitle(recordingJSON.getString("subtitle")); if (recordingJSON.has("seasonNumber")) builder.seriesNumber(recordingJSON.getInt("seasonNumber")); if (recordingJSON.has("episodeNum")) builder.episodeNumbers(parseEpisodeNumbers(recordingJSON)); if (recordingJSON.has("duration")) builder.secondsLong(recordingJSON.getInt("duration")); if (recordingJSON.has("startTime")) builder.recordedOn(parseUTCDateTime(recordingJSON.getString("startTime"))); if (recordingJSON.has("description")) builder.description(recordingJSON.getString("description")); if (recordingJSON.has("image")) builder.image(parseImages(recordingJSON)); if (recordingJSON.has("channel")) builder.channel(parseChannel(recordingJSON)); if (recordingJSON.has("originalAirdate")) builder.originalAirDate(LocalDate.parse(recordingJSON.getString("originalAirdate"), DateTimeFormatter.ofPattern("uuuu-MM-dd"))); if (recordingJSON.has("state")) builder.state(RecordingState.parse(recordingJSON.getString("state"))); if (recordingJSON.has("subscriptionIdentifier")) builder.reason(parseReason(recordingJSON.getJSONArray("subscriptionIdentifier"))); if (recordingJSON.has("drm")) builder.copyable(parseCopyable(recordingJSON.getJSONObject("drm"))); if (recordingJSON.has("expectedDeletion")) builder.expectedDeletion(parseUTCDateTime(recordingJSON.getString("expectedDeletion"))); } } return builder.build(); }
From source file:br.ufac.sion.dto.AuditoriaDTO.java
public String getDataAlteracaoFormatada() { DateTimeFormatter formatador = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy ' s ' HH:mm:ss z"); return revisao != null ? format.format(revisao.getRevisionDate()) : ""; }
From source file:fr.lepellerin.ecole.web.controller.cantine.DetaillerReservationRepasController.java
/** * initialise le form.//from ww w . java 2 s .c o m * * @return <code>DetaillerReservationRepasForm</code> */ @ModelAttribute("command") public DetaillerReservationRepasForm addCommand() { final DetaillerReservationRepasForm form = new DetaillerReservationRepasForm(); final YearMonth moisActuel = YearMonth.now(); final Integer intMois = Integer .valueOf(moisActuel.format(DateTimeFormatter.ofPattern(GeDateUtils.DATE_FORMAT_YYYYMM))); form.setAnneeMois(intMois); return form; }
From source file:svc.data.citations.datasources.mock.MockCitationDataSourceTest.java
@SuppressWarnings("unchecked") @Test/*from w w w . j ava2 s . c o m*/ public void returnsCitationsWhenGivenDOBLastNameAndMultipleMunicipalities() throws ParseException, IOException { final Violation VIOLATION = new Violation(); VIOLATION.id = 4; final List<Violation> VIOLATIONS = Lists.newArrayList(VIOLATION); final Citation CITATION = new Citation(); CITATION.id = 3; final List<Citation> CITATIONS = Lists.newArrayList(CITATION); Resource resource = mock(Resource.class); when(resource.getInputStream()).thenReturn(null); when(resourceLoader.getResource(CLASSPATH_URL_PREFIX + "sql/citation/get-by-location.sql")) .thenReturn(resource); when(jdbcTemplate.query(Matchers.anyString(), Matchers.anyMap(), Matchers.<RowMapper<Citation>>any())) .thenReturn(CITATIONS); String dateString = "08/05/1965"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); LocalDate date = LocalDate.parse(dateString, formatter); List<Citation> citations = mockCitationDataSource.getByNameAndMunicipalitiesAndDOB("someLastName", Lists.newArrayList(19L, 20L), date); when(violationManagerMock.getViolationsByCitationNumber(Matchers.anyString())).thenReturn(VIOLATIONS); assertThat(citations.get(0).id, is(3)); }
From source file:org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider.java
public OutputStream getOutputStream() throws Exception { String tempOutputFilePath = outputFilePath; String extension = RepositoryFilenameUtils.getExtension(tempOutputFilePath); if ("*".equals(extension)) { //$NON-NLS-1$ tempOutputFilePath = tempOutputFilePath.substring(0, tempOutputFilePath.lastIndexOf('.')); if (appendDateFormat != null) { try { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(appendDateFormat); String formattedDate = now.format(formatter); tempOutputFilePath += formattedDate; } catch (Exception e) { logger.warn("Unable to calculate current date: " + e.getMessage()); }/*ww w .j av a 2s . c om*/ } if (streamingAction != null) { String mimeType = streamingAction.getMimeType(null); if (mimeType != null && MimeHelper.getExtension(mimeType) != null) { tempOutputFilePath += MimeHelper.getExtension(mimeType); } } } RepositoryFileOutputStream outputStream = new RepositoryFileOutputStream(tempOutputFilePath, autoCreateUniqueFilename, true); outputStream.addListener(this); return outputStream; }
From source file:net.tradelib.core.Series.java
public double get(LocalDateTime ts, int colId) { int rowId = Collections.binarySearch(index, ts); if (rowId < 0) { throw new BadIndexException( ts.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " is not in the index"); }//w w w . j a v a 2s .c om return data.get(colId).get(rowId); }
From source file:squash.booking.lambdas.core.BookingManagerTest.java
@Before public void beforeTest() { // Set up the valid date range fakeCurrentDate = LocalDate.of(2015, 10, 6); fakeCurrentDateString = fakeCurrentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); bookingManager = new squash.booking.lambdas.core.BookingManagerTest.TestBookingManager(); bookingManager.setCurrentLocalDate(fakeCurrentDate); // Set up the test bookings existingName = "A.Shabana/J.Power"; newName = "J.Willstrop/N.Matthew"; existingSingleBooking = new Booking(2, 1, 3, 1, existingName); existingSingleBooking.setDate(fakeCurrentDateString); blockBookingOverlappingExistingSingleBooking = new Booking(1, 3, 3, 2, newName); blockBookingOverlappingExistingSingleBooking.setDate(fakeCurrentDateString); blockBookingOverlappingExistingBlockBooking = new Booking(2, 2, 9, 2, newName); blockBookingOverlappingExistingBlockBooking.setDate(fakeCurrentDateString); singleBookingOfFreeCourt = new Booking(4, 1, 12, 1, newName); singleBookingOfFreeCourt.setDate(fakeCurrentDateString); existingBlockBooking = new Booking(3, 3, 10, 2, existingName); existingBlockBooking.setDate(fakeCurrentDateString); singleBookingWithinExistingBlockBooking = new Booking(4, 1, 11, 1, newName); singleBookingWithinExistingBlockBooking.setDate(fakeCurrentDateString); blockBookingOfFreeCourts = new Booking(1, 5, 13, 3, newName); blockBookingOfFreeCourts.setDate(fakeCurrentDateString); bookingsBeforeCall = new ArrayList<>(); bookingsBeforeCall.add(existingSingleBooking); bookingsBeforeCall.add(existingBlockBooking); expectedBookingsAfterCall = new ArrayList<>(); mockery = new Mockery(); // Set up mock context mockContext = mockery.mock(Context.class); mockery.checking(new Expectations() { {/*from ww w. j a va 2 s . c o m*/ ignoring(mockContext); } }); // Set up mock logger mockLogger = mockery.mock(LambdaLogger.class); mockery.checking(new Expectations() { { ignoring(mockLogger); } }); // Set up mock lifecycle manager mockLifecycleManager = mockery.mock(ILifecycleManager.class); mockery.checking(new Expectations() { { ignoring(mockLifecycleManager); } }); bookingManager.setLifecycleManager(mockLifecycleManager); mockOptimisticPersister = mockery.mock(IOptimisticPersister.class); bookingManager.setOptimisticPersister(mockOptimisticPersister); adminSnsTopicArn = "adminSnsTopicArn"; bookingManager.setAdminSnsTopicArn(adminSnsTopicArn); }
From source file:org.edgexfoundry.scheduling.ScheduleContext.java
private ZonedDateTime parseTime(String time) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern(Schedule.DATETIME_FORMATS[0]) .withZone(ZoneId.systemDefault()); ZonedDateTime zdt = null;/*from www . ja va 2 s. c o m*/ try { zdt = ZonedDateTime.parse(time, dtf); } catch (DateTimeParseException e) { logger.error("parseTime() failed to parse '" + time + "'"); } return zdt; }
From source file:org.apache.geode.management.internal.cli.commands.ExportLogsDUnitTest.java
@Test public void startAndEndDateCanIncludeLogs() throws Exception { ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault()); ZonedDateTime yesterday = now.minusDays(1); ZonedDateTime tomorrow = now.plusDays(1); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ONLY_DATE_FORMAT); CommandStringBuilder commandStringBuilder = new CommandStringBuilder("export logs"); commandStringBuilder.addOption("start-time", dateTimeFormatter.format(yesterday)); commandStringBuilder.addOption("end-time", dateTimeFormatter.format(tomorrow)); commandStringBuilder.addOption("log-level", "debug"); gfshConnector.executeAndVerifyCommand(commandStringBuilder.toString()); Set<String> acceptedLogLevels = Stream.of("info", "error", "debug").collect(toSet()); verifyZipFileContents(acceptedLogLevels); }