List of usage examples for java.time YearMonth parse
public static YearMonth parse(CharSequence text, DateTimeFormatter formatter)
From source file:Main.java
public static void main(String[] args) { YearMonth y = YearMonth.parse("2013 09", DateTimeFormatter.ofPattern("yyyy MM")); System.out.println(y);/* w w w. j a v a 2 s .c om*/ }
From source file:fr.lepellerin.ecole.web.controller.cantine.DetaillerReservationRepasController.java
/** * init le model de la page details des reservations. * * @param model//from w w w. j av a 2 s . co m * : model spring * @return le nom de la vue * @throws TechnicalException */ @RequestMapping("/init") public String init(final Model model, @ModelAttribute("command") DetaillerReservationRepasForm form) throws TechnicalException { final CurrentUser user = (CurrentUser) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); final YearMonth moisActuel = YearMonth.parse(form.getAnneeMois().toString(), DateTimeFormatter.ofPattern(GeDateUtils.DATE_FORMAT_YYYYMM)); final PlanningDto planning = this.cantineService.getDateOuvert(moisActuel, user.getUser().getFamille()); model.addAttribute("planning", planning); return VUE; }
From source file:org.opensingular.form.type.util.STypeYearMonth.java
@Override public YearMonth convertNotNativeNotString(Object value) { if (value instanceof Integer) { return converterFromInteger((Integer) value); } else if (value instanceof Date) { Calendar cal = new GregorianCalendar(); cal.setTime((Date) value); return YearMonth.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1); } else if (value instanceof Calendar) { Calendar cal = (Calendar) value; return YearMonth.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1); } else if (value instanceof String) { return YearMonth.parse((String) value, formatter()); }/*w ww . ja va2 s. c om*/ throw createConversionError(value); }
From source file:org.opensingular.form.type.util.STypeYearMonth.java
@Override public YearMonth fromString(String value) { return StringUtils.isBlank(value) ? null : YearMonth.parse(value, formatter()); }
From source file:org.tightblog.util.Utilities.java
/** * Parse date as either 6-char or 8-char format. Use current date if date not provided * in URL (e.g., a permalink), more than 30 days in the future, or not valid */// w w w. ja va2 s . c om public static LocalDate parseURLDate(String dateString) { LocalDate ret = null; try { if (StringUtils.isNumeric(dateString)) { if (dateString.length() == 8) { ret = LocalDate.parse(dateString, Utilities.YMD_FORMATTER); } else if (dateString.length() == 6) { YearMonth tmp = YearMonth.parse(dateString, Utilities.YM_FORMATTER); ret = tmp.atDay(1); } } } catch (DateTimeParseException ignored) { ret = null; } // make sure the requested date is not more than a month in the future if (ret == null || ret.isAfter(LocalDate.now().plusDays(30))) { ret = LocalDate.now(); } return ret; }
From source file:sg.ncl.MainController.java
@PostMapping("/admin/statistics") public String adminUsageStatisticsQuery(@Valid @ModelAttribute("query") ProjectUsageQuery query, BindingResult result, RedirectAttributes attributes, HttpSession session) { if (!validateIfAdmin(session)) { return NO_PERMISSION_PAGE; }//ww w. ja va 2 s. co m List<ProjectDetails> newProjects = new ArrayList<>(); List<ProjectDetails> activeProjects = new ArrayList<>(); List<ProjectDetails> inactiveProjects = new ArrayList<>(); List<ProjectDetails> stoppedProjects = new ArrayList<>(); List<String> months = new ArrayList<>(); Map<String, MonthlyUtilization> utilizationMap = new HashMap<>(); Map<String, Integer> statsCategoryMap = new HashMap<>(); Map<String, Integer> statsAcademicMap = new HashMap<>(); int totalCategoryUsage = 0; int totalAcademicUsage = 0; if (result.hasErrors()) { StringBuilder message = new StringBuilder(); message.append(TAG_ERRORS); message.append(TAG_UL); for (ObjectError objectError : result.getAllErrors()) { FieldError fieldError = (FieldError) objectError; message.append(TAG_LI); message.append(fieldError.getField()); message.append(TAG_SPACE); message.append(fieldError.getDefaultMessage()); message.append(TAG_LI_CLOSE); } message.append(TAG_UL_CLOSE); attributes.addFlashAttribute(MESSAGE, message.toString()); } else { DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("MMM-yyyy").toFormatter(); YearMonth m_s = YearMonth.parse(query.getStart(), formatter); YearMonth m_e = YearMonth.parse(query.getEnd(), formatter); YearMonth counter = m_s; while (!counter.isAfter(m_e)) { String monthYear = counter.format(formatter); utilizationMap.put(monthYear, new MonthlyUtilization(monthYear)); months.add(monthYear); counter = counter.plusMonths(1); } List<ProjectDetails> projectsList = getProjects(); for (ProjectDetails project : projectsList) { // compute active and inactive projects differentiateProjects(newProjects, activeProjects, inactiveProjects, stoppedProjects, m_s, m_e, project); // monthly utilisation computeMonthlyUtilisation(utilizationMap, formatter, m_s, m_e, project); // usage statistics by category totalCategoryUsage += getCategoryUsage(statsCategoryMap, m_s, m_e, project); // usage statistics by academic institutes totalAcademicUsage += getAcademicUsage(statsAcademicMap, m_s, m_e, project); } } attributes.addFlashAttribute(KEY_QUERY, query); attributes.addFlashAttribute("newProjects", newProjects); attributes.addFlashAttribute("activeProjects", activeProjects); attributes.addFlashAttribute("inactiveProjects", inactiveProjects); attributes.addFlashAttribute("stoppedProjects", stoppedProjects); attributes.addFlashAttribute("months", months); attributes.addFlashAttribute("utilization", utilizationMap); attributes.addFlashAttribute("statsCategory", statsCategoryMap); attributes.addFlashAttribute("totalCategoryUsage", totalCategoryUsage); attributes.addFlashAttribute("statsAcademic", statsAcademicMap); attributes.addFlashAttribute("totalAcademicUsage", totalAcademicUsage); return "redirect:/admin/statistics"; }