List of usage examples for java.time LocalDate now
public static LocalDate now()
From source file:com.github.drbookings.ui.controller.UpcomingController.java
private static String getDateString(final LocalDate date) { if (LocalDate.now().equals(date)) { return "Today (" + date.toString() + ")"; } else if (LocalDate.now().plusDays(1).equals(date)) { return "Tomorrow (" + date.toString() + ")"; } else if (LocalDate.now().plusDays(2).equals(date) || LocalDate.now().plusDays(3).equals(date) || LocalDate.now().plusDays(4).equals(date)) { return "on " + date.getDayOfWeek().toString().charAt(0) + date.getDayOfWeek().toString().substring(1).toLowerCase() + " (" + date.toString() + ")"; } else {//from w ww .j a va 2s . c o m return "on " + date; } }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testEventGenerationWithUnboundedCategory() { List<TicketCategoryModification> categories = Arrays.asList( new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null), new TicketCategoryModification(null, "default", 9, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null), new TicketCategoryModification(null, "default", 0, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository) .getKey();// ww w . j a v a 2s .c o m List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId()); assertNotNull(tickets); assertFalse(tickets.isEmpty()); assertEquals(AVAILABLE_SEATS, tickets.size()); assertEquals(1, tickets.stream().filter(t -> t.getCategoryId() == null).count()); }
From source file:alfio.controller.ReservationFlowIntegrationTest.java
@Before public void ensureConfiguration() { IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository); List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> eventAndUser = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);//from w w w. ja v a 2s.c o m event = eventAndUser.getKey(); user = eventAndUser.getValue() + "_owner"; // TemplateManager templateManager = Mockito.mock(TemplateManager.class); reservationApiController = new ReservationApiController(eventRepository, ticketHelper, templateManager, i18nManager, euVatChecker, ticketReservationRepository, ticketReservationManager); }
From source file:co.com.soinsoftware.hotelero.view.JFRoomPayment.java
private Date getFinalDate(final Date initialDate, final int hour) { final LocalDate today = LocalDate.now(); LocalDateTime finalDateTime = null; if (DateUtils.isSameDay(initialDate, new Date())) { finalDateTime = today.plusDays(1).atTime(LocalTime.of(hour, 0)); } else {//from w ww .j a v a2 s . c o m finalDateTime = today.atTime(LocalTime.of(hour, 0)); } final ZonedDateTime zdt = finalDateTime.atZone(ZoneId.systemDefault()); return Date.from(zdt.toInstant()); }
From source file:alfio.manager.AdminReservationManagerIntegrationTest.java
@Test public void testReserveFromExistingCategoryNotEnoughSeatsNoExtensionAllowedBounded() throws Exception { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null)); performExistingCategoryTest(categories, true, Collections.singletonList(AVAILABLE_SEATS + 1), false, false, 0, AVAILABLE_SEATS);//from w w w . j a v a 2 s. c om }
From source file:mesclasses.view.JourneeController.java
/** * Initializes the controller class.//from www . ja v a2s .c o m */ @Override public void initialize(URL url, ResourceBundle rb) { LogUtil.logStart(); name = "Journee Ctrl"; super.initialize(url, rb); LOG.debug("Initialisation de " + name); initTabs(); Btns.makeLeft(previousDayBtn); Btns.makeRight(nextDayBtn); Btns.makeLeft(seanceSelect.getBtnLeft()); Btns.makeRight(seanceSelect.getBtnRight()); Btns.makeAdd(addCoursBtn); Btns.makeDelete(remCoursBtn); Btns.tooltip(previousDayBtn, "Jour prcdent"); Btns.tooltip(nextDayBtn, "Jour suivant"); Btns.tooltip(seanceSelect.getBtnLeft(), "Sance prcdente"); Btns.tooltip(seanceSelect.getBtnRight(), "Sance suivante"); Btns.tooltip(addCoursBtn, "Ajouter une sance ponctuelle"); Btns.tooltip(remCoursBtn, "Supprimer la sance ponctuelle"); Btns.tooltip(switchNonActifsBtn, "active/dsactive l'affichage des lves inactifs"); Btns.tooltip(rapportsBtn, "Ouvre la page des rapports trimestriels pour la classe"); Btns.tooltip(punitionsBtn, "Ouvre le suivi des punitions, devoirs et mots pour la classe"); Btns.tooltip(postItBtn, "ouvre le postIt de la classe"); Btns.tooltip(ramasserBtn, "ouvre la fentre des actions faire pour la classe"); currentDate.setDayCellFactory(new TunedDayCellFactory().setAllowSundays(false)); currentDate.setConverter(NodeUtil.DATE_WITH_DAY_NAME); currentDate.valueProperty().addListener(dateListener); displayNonActifs = new SimpleBooleanProperty(false); switchNonActifsBtn.setText("Afficher inactifs"); displayNonActifs.addListener((observable, oldValue, newValue) -> { LOG.debug("Switch actifs/inactifs"); switchNonActifsBtn.setText(displayNonActifs.get() ? "Masquer inactifs" : "Afficher inactifs"); refreshGrid(); }); seanceSelect.addChangeListener((ob, o, n) -> { LOG.debug("seanceSelect changed --> reloading"); loadCurrentSeance(); }); // activation du bouton remCours si besoin rapportsBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty())); punitionsBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty())); postItBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty())); // on ne change que la date, le listener sur currentDate se charge du reste LocalDate today = LocalDate.now(); if (today.getDayOfWeek().equals(DayOfWeek.SUNDAY)) { today = today.minusDays(1); } LOG.debug("Initializing with today's date"); currentDate.setValue(today); LogUtil.logEnd(); }
From source file:at.yawk.buycraft.web.HttpWebApi.java
@Override public void registerCoupon(Coupon coupon) throws IOException, CouponException { List<NameValuePair> reqPairs = new ArrayList<>(); String csrf = loadCouponCsrf(); reqPairs.add(new BasicNameValuePair("csrf", csrf)); if (coupon.getBasketTypes().contains(BasketType.SINGLE)) { if (coupon.getBasketTypes().contains(BasketType.SUBSCRIPTION)) { reqPairs.add(new BasicNameValuePair("basket_type", "both")); } else {/*from ww w. ja v a 2 s . c o m*/ reqPairs.add(new BasicNameValuePair("basket_type", "subscription")); } } else { // without basket type would be invalid, should be checked in CouponBuilder reqPairs.add(new BasicNameValuePair("basket_type", "single")); } reqPairs.add(new BasicNameValuePair("code", coupon.getCode())); switch (coupon.getDiscountType()) { case AMOUNT: reqPairs.add(new BasicNameValuePair("discount_type", "value")); reqPairs.add( new BasicNameValuePair("discount_amount", String.format("%.2f", coupon.getDiscountAmount()))); reqPairs.add(new BasicNameValuePair("discount_percentage", "0")); break; case PERCENTAGE: reqPairs.add(new BasicNameValuePair("discount_type", "percentage")); reqPairs.add(new BasicNameValuePair("discount_amount", "0.00")); reqPairs.add(new BasicNameValuePair("discount_percentage", Double.toString(coupon.getDiscountFraction() * 100))); break; } switch (coupon.getExpiryType()) { case NEVER: reqPairs.add(new BasicNameValuePair("expire_type", "never")); reqPairs.add(new BasicNameValuePair("expire_limit", "0")); reqPairs.add(new BasicNameValuePair("expire_timestamp", LocalDate.now().format(DATE_FORMATTER))); break; case DATE: reqPairs.add(new BasicNameValuePair("expire_type", "timestamp")); reqPairs.add(new BasicNameValuePair("expire_timestamp", coupon.getExpiryDate().format(DATE_FORMATTER))); reqPairs.add(new BasicNameValuePair("expire_limit", "0")); break; case REDEEM_COUNT: reqPairs.add(new BasicNameValuePair("expire_type", "limit")); reqPairs.add(new BasicNameValuePair("expire_limit", Integer.toString(coupon.getExpiryRedeemCount()))); reqPairs.add(new BasicNameValuePair("expire_timestamp", LocalDate.now().format(DATE_FORMATTER))); break; } reqPairs.add(new BasicNameValuePair("minimum", String.format("%.2f", coupon.getMinimumBasketValue()))); reqPairs.add(new BasicNameValuePair("start_time", coupon.getStartDate().format(DATE_FORMATTER))); reqPairs.add(new BasicNameValuePair("user_limit", Integer.toString(coupon.getMaximumUserUses()))); switch (coupon.getEffectType()) { case CART: reqPairs.add(new BasicNameValuePair("type", "cart")); break; case CATEGORIES: for (int category : coupon.getCategoryIds()) { reqPairs.add(new BasicNameValuePair("categories[]", Integer.toString(category))); } reqPairs.add(new BasicNameValuePair("type", "category")); break; case PACKAGES: for (int packageId : coupon.getPackages()) { reqPairs.add(new BasicNameValuePair("packages[]", Integer.toString(packageId))); } reqPairs.add(new BasicNameValuePair("type", "package")); break; } HttpPost request = new HttpPost("https://server.buycraft.net/coupons/add"); request.addHeader("X-Requested-With", "XMLHttpRequest"); request.setEntity(new UrlEncodedFormEntity(reqPairs)); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); Header encoding = entity.getContentEncoding(); JsonObject json = new JsonParser() .parse(new InputStreamReader(entity.getContent(), encoding == null ? "UTF-8" : encoding.getValue())) .getAsJsonObject(); if (json.get("type").getAsString().equals("error")) { throw new CouponException(json.get("message").toString()); } }
From source file:org.wallride.service.PostService.java
/** * * @param blogLanguage//from w ww . j av a2s . co m * @param type * @param maxRank * @see PostService#getPopularPosts(String, PopularPost.Type) */ @CacheEvict(value = WallRideCacheConfiguration.POPULAR_POST_CACHE, key = "'list.type.' + #blogLanguage.language + '.' + #type") public void updatePopularPosts(BlogLanguage blogLanguage, PopularPost.Type type, int maxRank) { logger.info("Start update of the popular posts"); GoogleAnalytics googleAnalytics = blogLanguage.getBlog().getGoogleAnalytics(); if (googleAnalytics == null) { logger.info("Configuration of Google Analytics can not be found"); return; } Analytics analytics = GoogleAnalyticsUtils.buildClient(googleAnalytics); WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext, "org.springframework.web.servlet.FrameworkServlet.CONTEXT.guestServlet"); if (context == null) { logger.info("GuestServlet is not ready yet"); return; } final RequestMappingHandlerMapping mapping = context.getBean(RequestMappingHandlerMapping.class); Map<Post, Long> posts = new LinkedHashMap<>(); int startIndex = 1; int currentRetry = 0; int totalResults = 0; do { try { LocalDate now = LocalDate.now(); LocalDate startDate; switch (type) { case DAILY: startDate = now.minusDays(1); break; case WEEKLY: startDate = now.minusWeeks(1); break; case MONTHLY: startDate = now.minusMonths(1); break; default: throw new ServiceException(); } DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); Analytics.Data.Ga.Get get = analytics.data().ga() .get(googleAnalytics.getProfileId(), startDate.format(dateTimeFormatter), now.format(dateTimeFormatter), "ga:sessions") .setDimensions(String.format("ga:pagePath", googleAnalytics.getCustomDimensionIndex())) .setSort(String.format("-ga:sessions", googleAnalytics.getCustomDimensionIndex())) .setStartIndex(startIndex).setMaxResults(GoogleAnalyticsUtils.MAX_RESULTS); if (blogLanguage.getBlog().isMultiLanguage()) { get.setFilters("ga:pagePath=~/" + blogLanguage.getLanguage() + "/"); } logger.info(get.toString()); final GaData gaData = get.execute(); if (CollectionUtils.isEmpty(gaData.getRows())) { break; } for (List row : gaData.getRows()) { UriComponents uriComponents = UriComponentsBuilder.fromUriString((String) row.get(0)).build(); MockHttpServletRequest request = new MockHttpServletRequest(servletContext); request.setRequestURI(uriComponents.getPath()); request.setQueryString(uriComponents.getQuery()); MockHttpServletResponse response = new MockHttpServletResponse(); BlogLanguageRewriteRule rewriteRule = new BlogLanguageRewriteRule(blogService); BlogLanguageRewriteMatch rewriteMatch = (BlogLanguageRewriteMatch) rewriteRule.matches(request, response); try { rewriteMatch.execute(request, response); } catch (ServletException e) { throw new ServiceException(e); } catch (IOException e) { throw new ServiceException(e); } request.setRequestURI(rewriteMatch.getMatchingUrl()); HandlerExecutionChain handler; try { handler = mapping.getHandler(request); } catch (Exception e) { throw new ServiceException(e); } if (!(handler.getHandler() instanceof HandlerMethod)) { continue; } HandlerMethod method = (HandlerMethod) handler.getHandler(); if (!method.getBeanType().equals(ArticleDescribeController.class) && !method.getBeanType().equals(PageDescribeController.class)) { continue; } // Last path mean code of post String code = uriComponents.getPathSegments().get(uriComponents.getPathSegments().size() - 1); Post post = postRepository.findOneByCodeAndLanguage(code, rewriteMatch.getBlogLanguage().getLanguage()); if (post == null) { logger.debug("Post not found [{}]", code); continue; } if (!posts.containsKey(post)) { posts.put(post, Long.parseLong((String) row.get(1))); } if (posts.size() >= maxRank) { break; } } if (posts.size() >= maxRank) { break; } startIndex += GoogleAnalyticsUtils.MAX_RESULTS; totalResults = gaData.getTotalResults(); } catch (IOException e) { logger.warn("Failed to synchronize with Google Analytics", e); if (currentRetry >= GoogleAnalyticsUtils.MAX_RETRY) { throw new GoogleAnalyticsException(e); } currentRetry++; logger.info("{} ms to sleep...", GoogleAnalyticsUtils.RETRY_INTERVAL); try { Thread.sleep(GoogleAnalyticsUtils.RETRY_INTERVAL); } catch (InterruptedException ie) { throw new GoogleAnalyticsException(e); } logger.info("Retry for the {} time", currentRetry); } } while (startIndex <= totalResults); popularPostRepository.deleteByType(blogLanguage.getLanguage(), type); int rank = 1; for (Map.Entry<Post, Long> entry : posts.entrySet()) { PopularPost popularPost = new PopularPost(); popularPost.setLanguage(blogLanguage.getLanguage()); popularPost.setType(type); popularPost.setRank(rank); popularPost.setViews(entry.getValue()); popularPost.setPost(entry.getKey()); popularPostRepository.saveAndFlush(popularPost); rank++; } logger.info("Complete the update of popular posts"); }
From source file:com.romeikat.datamessie.core.base.ui.page.StatisticsPage.java
private LocalDate getToDate() { return LocalDate.now(); }
From source file:edu.mum.cs545.recipebook.controller.MenuBean.java
public void addComment() { System.out.println("Add comment called"); if (newCommentName == null || newCommentName.isEmpty()) { newCommentName = "Anonymous"; }//from ww w. j a va 2 s . c o m menuService.addNewComment(new CommentEntity(selectedMenuItem, newCommentName, LocalDate.now(), newComment)); commentsForSelectedMenuItem = menuService.getComments(selectedMenuItem); newComment = ""; newCommentName = ""; ratingValue = 0; }