List of usage examples for java.time LocalDate of
public static LocalDate of(int year, int month, int dayOfMonth)
From source file:fi.luontola.cqrshotel.JsonSerializationTest.java
private static Object randomValue(Class<?> type) { ThreadLocalRandom random = ThreadLocalRandom.current(); if (type == UUID.class) { return UUID.randomUUID(); }/*from w w w .j av a 2 s.com*/ if (type == LocalDate.class) { return LocalDate.of(random.nextInt(2000, 2100), random.nextInt(Month.JANUARY.getValue(), Month.DECEMBER.getValue() + 1), random.nextInt(1, Month.FEBRUARY.minLength() + 1)); } if (type == Money.class) { return Money.of(random.nextDouble(0, 1000), pickRandom(Monetary.getCurrencies())); } if (type == Instant.class) { return Instant.ofEpochMilli(random.nextLong()); } if (type == String.class) { return RandomStringUtils.randomAlphanumeric(random.nextInt(10)); } if (type == int.class) { return random.nextInt(); } throw new IllegalArgumentException("Unsupported type: " + type); }
From source file:example.springdata.cassandra.java8.Jsr310IntegrationTests.java
@Test public void findOneByConvertedTypes() { Order order = new Order("42", LocalDate.of(2010, 1, 2), ZoneId.systemDefault()); repository.save(order);// w w w . jav a 2 s. co m com.datastax.driver.core.LocalDate date = com.datastax.driver.core.LocalDate.fromYearMonthDay(2010, 1, 2); String zoneId = order.getZoneId().getId(); assertThat(repository.findOrderByDate(date, zoneId), is(equalTo(order))); }
From source file:example.app.core.mapping.json.jackson.serialization.LocalDateDeserializer.java
@Override public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException { JsonNode node = parser.getCodec().readTree(parser); int dayOfMonth = node.get("dayOfMonth").asInt(); int year = node.get("year").asInt(); Month month = Month.valueOf(node.get("month").asText()); return LocalDate.of(year, month, dayOfMonth); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivateWorkExperienceResourceTest.java
@Test public void thatPortfolioWorkExperienceIsSaved() throws Exception { WorkExperienceDto workExperienceDto = new WorkExperienceDto(); workExperienceDto.employer = "Helsingin Yliopisto"; workExperienceDto.jobTitle = "Toimitusjohtaja"; workExperienceDto.startDate = LocalDate.of(2016, 6, 6); workExperienceDto.endDate = LocalDate.of(2016, 7, 6); mockMvc.perform(post(RESOURCE_URL).with(securityContext(studentSecurityContext())) .content(WebTestUtils.toJsonBytes(workExperienceDto)).contentType(MediaType.APPLICATION_JSON) .characterEncoding("UTF-8").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(jsonPath("$.jobTitle").value(workExperienceDto.jobTitle)) .andExpect(jsonPath("$.employer").value(workExperienceDto.employer)) .andExpect(jsonPath("$.startDate[0]").value(workExperienceDto.startDate.getYear())) .andExpect(jsonPath("$.startDate[1]").value(workExperienceDto.startDate.getMonthValue())) .andExpect(jsonPath("$.startDate[2]").value(workExperienceDto.startDate.getDayOfMonth())) .andExpect(jsonPath("$.endDate[0]").value(workExperienceDto.endDate.getYear())) .andExpect(jsonPath("$.endDate[1]").value(workExperienceDto.endDate.getMonthValue())) .andExpect(jsonPath("$.endDate[2]").value(workExperienceDto.endDate.getDayOfMonth())); }
From source file:defaultmethods.SimpleTimeClient.java
public void setDateAndTime(int day, int month, int year, int hour, int minute, int second) { LocalDate dateToSet = LocalDate.of(day, month, year); LocalTime timeToSet = LocalTime.of(hour, minute, second); dateAndTime = LocalDateTime.of(dateToSet, timeToSet); }
From source file:com.thinkenterprise.domain.BoundedContextInitializer.java
private void initRoutes() { // Mnchen-Houston LH7902 ////w ww . j a v a 2 s. c o m Route route = new Route("LH7902", "MUC", "IAH"); route.addScheduledDaily(); route.setDepartureTime(LocalTime.of(9, 30)); route.setArrivalTime(LocalTime.of(14, 00)); // Flug am 23.09.2015 Flight flight = new Flight(120.45, LocalDate.of(2015, 9, 23)); flight.addEmployee("Fred"); flight.addEmployee("Sarah"); route.addFlight(flight); // Flug am 24.09.2015 flight = new Flight(111.45, LocalDate.of(2015, 9, 24)); route.addFlight(flight); routeRepository.save(route); // Mnchen-Ibiza LH1602 // route = new Route("LH1602", "MUC", "IBZ"); route.addScheduledWeekday(DayOfWeek.SATURDAY); route.setDepartureTime(LocalTime.of(8, 50)); route.setArrivalTime(LocalTime.of(11, 15)); flight = new Flight(120.45, LocalDate.of(2015, 9, 19)); route.addFlight(flight); routeRepository.save(route); // Mnchen-Ibiza LH1838 // route = new Route("LH1838", "MUC", "IBZ"); route.addScheduledWeekday(DayOfWeek.MONDAY); route.addScheduledWeekday(DayOfWeek.THURSDAY); route.addScheduledWeekday(DayOfWeek.SATURDAY); route.setDepartureTime(LocalTime.of(12, 25)); route.setArrivalTime(LocalTime.of(14, 50)); flight = new Flight(120.45, LocalDate.of(2015, 9, 19)); route.setAircraft("D-AIPA"); route.addFlight(flight); routeRepository.save(route); // Mnchen-New York LH401 // route = new Route("LH401", "FRA", "NYC"); route.addScheduledDaily(); route.setDepartureTime(LocalTime.of(15, 55)); route.setArrivalTime(LocalTime.of(5, 30)); flight = new Flight(120.45, LocalDate.of(2015, 9, 30)); route.setAircraft("D-AIPA"); route.addFlight(flight); routeRepository.save(route); }
From source file:fixio.netty.codec.FixMessageDecoderTest.java
@Test public void testDecode() throws Exception { List<Object> result = decode( "8=FIX.4.1\u00019=90\u000135=0\u000149=INVMGR\u000156=BRKR\u000134=240\u000152=19980604-08:03:31\u000110=129\u0001"); assertEquals(1, result.size());/*from w w w . j a v a 2 s . c om*/ assertTrue(result.get(0) instanceof FixMessageImpl); final FixMessageImpl fixMessage = (FixMessageImpl) result.get(0); FixMessageHeader header = fixMessage.getHeader(); assertEquals("FIX.4.1", fixMessage.getHeader().getBeginString()); assertEquals(MessageTypes.HEARTBEAT, fixMessage.getMessageType()); assertEquals("INVMGR", header.getSenderCompID()); assertEquals("BRKR", header.getTargetCompID()); assertEquals(240, header.getMsgSeqNum()); assertEquals(129, fixMessage.getChecksum()); final Long value = fixMessage.getValue(FieldType.SendingTime); assertEquals(ZonedDateTime.of(LocalDate.of(1998, 6, 4), LocalTime.of(8, 3, 31), systemUTC().zone()) .toInstant().toEpochMilli(), value.longValue()); }
From source file:cz.muni.fi.pv168.AgentManagerImplTest.java
@Test(expected = IllegalArgumentException.class) public void createAgentWithWrongId() throws Exception { Agent agent = newAgent("James Bond", LocalDate.of(1950, 1, 1)); agent.setId(1L);//w ww. ja v a2s . c o m manager.createAgent(agent); }
From source file:org.wallride.web.controller.guest.article.ArticleDescribeController.java
@RequestMapping public String describe(@PathVariable int year, @PathVariable int month, @PathVariable int day, @PathVariable String code, BlogLanguage blogLanguage, Model model, RedirectAttributes redirectAttributes) { Article article = articleService.getArticleByCode(code, blogLanguage.getLanguage()); if (article == null) { article = articleService.getArticleByCode(code, blogLanguage.getBlog().getDefaultLanguage()); }//from w w w . j a v a2 s .c om if (article == null) { throw new HttpNotFoundException(); } if (article.getStatus() != Post.Status.PUBLISHED) { throw new HttpNotFoundException(); } LocalDate date = LocalDate.of(year, month, day); if (!article.getDate().toLocalDate().equals(date)) { redirectAttributes.addAttribute("year", article.getDate().getYear()); redirectAttributes.addAttribute("month", article.getDate().getMonth().getValue()); redirectAttributes.addAttribute("day", article.getDate().getDayOfMonth()); redirectAttributes.addAttribute("code", code); return "redirect:/{year}/{month}/{day}/{code}"; } CommentSearchRequest request = new CommentSearchRequest(); request.setPostId(article.getId()); request.setApproved(Boolean.TRUE); Page<Comment> comments = commentService.getComments(request, new PageRequest(0, 1000)); List<Long> ids = articleService.getArticleIds(new ArticleSearchRequest().withStatus(Post.Status.PUBLISHED)); if (!CollectionUtils.isEmpty(ids)) { int index = ids.indexOf(article.getId()); if (index < ids.size() - 1) { Article next = articleService.getArticleById(ids.get(index + 1)); model.addAttribute("next", next); } if (index > 0) { Article prev = articleService.getArticleById(ids.get(index - 1)); model.addAttribute("prev", prev); } } model.addAttribute("article", article); model.addAttribute("comments", comments); return "article/describe"; }
From source file:org.primeframework.mvc.parameter.convert.converters.LocalDateConverterTest.java
@Test public void toStrings() { GlobalConverter converter = new LocalDateConverter(new MockConfiguration()); String str = converter.convertToString(LocalDate.class, null, "testExpr", null); assertNull(str);//from w w w.java 2 s . co m str = converter.convertToString(LocalDate.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr", LocalDate.of(2008, 7, 8)); assertEquals(str, "07-08-2008"); }