List of usage examples for java.time LocalDateTime getMonth
public Month getMonth()
From source file:Main.java
public static void main(String[] args) { LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01); System.out.println(a.getMonth().name()); }
From source file:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java
/** * Validate the MultiTypeObject based on the object build with the method * 'buildMultiTypeObject'//ww w . j a va 2s .c o m * * @param toValidate * the object to validate */ public static void validateMultiTypeObject(MultiTypeObject toValidate) { MultiTypeObject base = buildMultiTypeObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR)); assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH)); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH)); LocalDate localDate = LocalDate.now(); assertEquals(localDate.getDayOfMonth(), toValidate.getLocalDateAttribute().getDayOfMonth()); assertEquals(localDate.getMonth(), toValidate.getLocalDateAttribute().getMonth()); assertEquals(localDate.getYear(), toValidate.getLocalDateAttribute().getYear()); LocalDateTime localDateTime = LocalDateTime.now(); assertEquals(localDateTime.getDayOfMonth(), toValidate.getLocalDateTimeAttribute().getDayOfMonth()); assertEquals(localDateTime.getMonth(), toValidate.getLocalDateTimeAttribute().getMonth()); assertEquals(localDateTime.getYear(), toValidate.getLocalDateTimeAttribute().getYear()); assertEquals(localDateTime.getHour(), toValidate.getLocalDateTimeAttribute().getHour()); /* it is possible to have an error below due the time of execution of the test */ assertEquals(localDateTime.getMinute(), toValidate.getLocalDateTimeAttribute().getMinute()); assertEquals(base.getStringAttribute(), toValidate.getStringAttribute()); assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute()); assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute()); assertEquals(base.getLongAttribute(), toValidate.getLongAttribute()); assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute()); assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode()); assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily()); assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName()); assertEquals(base.getIntegerPrimitiveAttribute(), toValidate.getIntegerPrimitiveAttribute()); assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute()); assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute()); assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute()); assertEquals(base.getAddressInfo().getAddress(), toValidate.getAddressInfo().getAddress()); assertEquals(base.getAddressInfo().getNumber(), toValidate.getAddressInfo().getNumber()); assertEquals(base.getAddressInfo().getCity(), toValidate.getAddressInfo().getCity()); assertEquals(base.getAddressInfo().getCityCode(), toValidate.getAddressInfo().getCityCode()); assertEquals(base.getAddressInfo().getCountry(), toValidate.getAddressInfo().getCountry()); assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute()); assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute()); assertEquals(base.getUnitFamily(), toValidate.getUnitFamily()); assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute()); assertEquals(base.getShortAttribute(), toValidate.getShortAttribute()); assertEquals(base.getShortPrimitiveAttribute(), toValidate.getShortPrimitiveAttribute()); // TODO add new validation below }
From source file:org.wallride.web.controller.guest.article.ArticleIndexController.java
@RequestMapping("/{year:[0-9]{4}}/{month:[0-9]{2}}") public String month(@PathVariable int year, @PathVariable int month, @PageableDefault(10) Pageable pageable, BlogLanguage blogLanguage, HttpServletRequest servletRequest, Model model) { ArticleSearchForm form = new ArticleSearchForm() { };//from w ww. ja va 2s .c om form.setLanguage(blogLanguage.getLanguage()); LocalDateTime date = LocalDateTime.of(year, month, 1, 0, 0, 0); form.setDateFrom(LocalDateTime.of(year, month, 1, 0, 0, 0)); form.setDateTo(LocalDateTime.of(year, month, date.getMonth().length(true), 23, 59, 59)); Page<Article> articles = articleService.getArticles(form.toArticleSearchRequest(), pageable); model.addAttribute("articles", articles); model.addAttribute("pageable", pageable); model.addAttribute("pagination", new Pagination<>(articles, servletRequest)); return "article/index"; }
From source file:de.steilerdev.myVerein.server.controller.admin.EventManagementController.java
/** * Returns all events, that are taking place on a specified date. The date parameter needs to be formatted according to the following pattern: YYYY/MM/DD. This function is invoked by GETting the URI /api/admin/event/date * @param date The selected date, correctly formatted (YYYY/MM/DD) * @return An HTTP response with a status code. If the function succeeds, a list of events is returned, otherwise an error code is returned. *//* www . ja va 2 s . c o m*/ @RequestMapping(value = "date", produces = "application/json", method = RequestMethod.GET) public ResponseEntity<List<Event>> getEventsOfDate(@RequestParam String date, @CurrentUser User currentUser) { logger.trace("[" + currentUser + "] Getting events of date " + date); LocalDateTime startOfDay, endOfDay, startOfMonth, endOfMonth; ArrayList<Event> eventsOfDay = new ArrayList<>(); try { // Get start of day and start of next day startOfDay = LocalDate.parse(date, DateTimeFormatter.ISO_LOCAL_DATE).atStartOfDay(); endOfDay = startOfDay.plusDays(1); startOfMonth = LocalDate.of(startOfDay.getYear(), startOfDay.getMonth(), 1).atStartOfDay(); endOfMonth = startOfMonth.plusMonths(1); logger.debug("[" + currentUser + "] Converted to date object: " + startOfDay.toString()); } catch (DateTimeParseException e) { logger.warn("[" + currentUser + "] Unable to parse date: " + date + ": " + e.toString()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } logger.debug("Getting all single day events..."); eventsOfDay.addAll(eventRepository.findAllByStartDateTimeBetweenAndMultiDate(startOfDay, endOfDay, false)); logger.debug("All single day events retrieved, got " + eventsOfDay.size() + " events so far"); logger.debug("Getting all multi day events..."); //Collecting all multi date events, that either start or end within the selected month (which means that events that are spanning over several months are not collected) eventsOfDay.addAll(Stream.concat( eventRepository.findAllByStartDateTimeBetweenAndMultiDate(startOfMonth, endOfMonth, true).stream(), //All multi date events starting within the month eventRepository.findAllByEndDateTimeBetweenAndMultiDate(startOfMonth, endOfMonth, true).stream()) //All multi date events ending within the month .distinct() //Removing all duplicated events .parallel() .filter(event -> event.getStartDate().isEqual(startOfDay.toLocalDate()) || event.getEndDate().isEqual(startOfDay.toLocalDate()) || (event.getEndDate().isAfter(endOfDay.toLocalDate()) && event.getStartDate().isBefore(startOfDay.toLocalDate()))) //Filter all multi date events that do not span over the date .collect(Collectors.toList())); logger.debug("All multi day events gathered, got " + eventsOfDay.size() + " events so far"); if (eventsOfDay.isEmpty()) { logger.warn("[" + currentUser + "] The events list of " + date + " is empty"); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } else { eventsOfDay.replaceAll(Event::getSendingObjectOnlyNameTimeId); logger.debug("[" + currentUser + "] Returning " + eventsOfDay.size() + " events for " + date); return new ResponseEntity<>(eventsOfDay, HttpStatus.OK); } }
From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java
/** * Returns CRON expression from the provided {@link LocalDateTime} instance * * @param localDateTime the {@link LocalDateTime} instance * @return the CRON expression/*from w w w . j av a2 s. c om*/ * @throws NullPointerException * if {@code localDateTime} is null */ public static String createCronFromTemporal(LocalDateTime localDateTime) { requireNonNull(localDateTime, "Temporal instance cannot be null"); int minute = localDateTime.getMinute(); int hour = localDateTime.getHour(); int day = localDateTime.getDayOfMonth(); int month = localDateTime.getMonth().getValue(); int year = localDateTime.getYear(); StringBuilder builder = new StringBuilder(); builder.append(SECONDS).append(SPACE).append(minute).append(SPACE).append(hour).append(SPACE).append(day) .append(SPACE).append(month).append(SPACE).append(DAYS_OF_WEEK).append(SPACE).append(year); return builder.toString(); }