Example usage for java.time LocalDate now

List of usage examples for java.time LocalDate now

Introduction

In this page you can find the example usage for java.time LocalDate now.

Prototype

public static LocalDate now() 

Source Link

Document

Obtains the current date from the system clock in the default time-zone.

Usage

From source file:onl.identitas.identity.ejb.entities.Sprint.java

public Sprint() {
    this.startDate = LocalDate.now();
}

From source file:org.jboss.jbossset.CommandLineParser.java

private LocalDate getValidLocalDate(String date, String optionName) throws ParseException {
    try {/*from w  w  w .j  a  va2s .co m*/
        LocalDate localDate = LocalDate.parse(date);
        if (optionName.equals("startDate") && localDate.isAfter(LocalDate.now()))
            throw new ParseException("startDate cannot be in the future.");
        return localDate;
    } catch (DateTimeParseException e) {
        throw new ParseException("Invalid " + optionName + ". Date format must be YYYY-MM-DD.");
    }
}

From source file:alfio.test.util.IntegrationTestUtil.java

public static Pair<Event, String> initEvent(List<TicketCategoryModification> categories,
        OrganizationRepository organizationRepository, UserManager userManager, EventManager eventManager,
        EventRepository eventRepository) {

    String organizationName = UUID.randomUUID().toString();
    String username = UUID.randomUUID().toString();
    String eventName = UUID.randomUUID().toString();

    userManager.createOrganization(organizationName, "org", "email@example.com");
    Organization organization = organizationRepository.findByName(organizationName).get();
    userManager.insertUser(organization.getId(), username, "test", "test", "test@example.com", Role.OPERATOR,
            User.Type.INTERNAL);
    userManager.insertUser(organization.getId(), username + "_owner", "test", "test", "test@example.com",
            Role.OWNER, User.Type.INTERNAL);

    LocalDateTime expiration = LocalDateTime.now().plusDays(5).plusHours(1);

    Map<String, String> desc = new HashMap<>();
    desc.put("en", "muh description");
    desc.put("it", "muh description");
    desc.put("de", "muh description");

    EventModification em = new EventModification(null, Event.EventType.INTERNAL, "url", "url", "url", "url",
            null, eventName, "event display name", organization.getId(), "muh location", "0.0", "0.0",
            ZoneId.systemDefault().getId(), desc,
            new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()),
            new DateTimeModification(expiration.toLocalDate(), expiration.toLocalTime()), BigDecimal.TEN, "CHF",
            AVAILABLE_SEATS, BigDecimal.ONE, true, Collections.singletonList(PaymentProxy.OFFLINE), categories,
            false, new LocationDescriptor("", "", "", ""), 7, null, null);
    eventManager.createEvent(em);/*from w w w.  j a v a  2 s .c  o m*/
    Event event = eventManager.getSingleEvent(eventName, username);
    Assert.assertEquals(AVAILABLE_SEATS, eventRepository.countExistingTickets(event.getId()).intValue());
    return Pair.of(event, username);
}

From source file:alfio.manager.WaitingQueueProcessorIntegrationTest.java

@Test
public void testPreRegistration() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()),
            new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.TEN,
            false, "", false, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);/*  w w w .j  a  v  a 2s .  c  o  m*/
    Event event = pair.getKey();
    waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event),
            "peppino@garibaldi.com", null, Locale.ENGLISH);
    waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event),
            "bixio@mille.org", null, Locale.ITALIAN);
    assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);

    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size());

    TicketCategoryModification tcm = new TicketCategoryModification(null, "default", 10,
            new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()),
            new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()), DESCRIPTION, BigDecimal.TEN,
            false, "", true, null, null, null, null, null);
    eventManager.insertCategory(event.getId(), tcm, pair.getValue());

    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);

    List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
    assertEquals(2, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
    assertTrue(subscriptions.stream()
            .allMatch(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)));
    assertTrue(subscriptions.stream()
            .allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.PRE_SALES)));

}

From source file:org.openmhealth.shim.fitbit.FitbitShim.java

@Override
public ShimDataResponse getData(ShimDataRequest shimDataRequest) throws ShimException {

    AccessParameters accessParameters = shimDataRequest.getAccessParameters();
    String accessToken = accessParameters.getAccessToken();
    String tokenSecret = accessParameters.getTokenSecret();

    FitbitDataType fitbitDataType;//from   www .ja v  a  2 s.  c o m
    try {
        fitbitDataType = FitbitDataType.valueOf(shimDataRequest.getDataTypeKey().trim().toUpperCase());
    } catch (NullPointerException | IllegalArgumentException e) {
        throw new ShimException("Null or Invalid data type parameter: " + shimDataRequest.getDataTypeKey()
                + " in shimDataRequest, cannot retrieve data.");
    }

    /***
     * Setup default date parameters
     */
    OffsetDateTime today = LocalDate.now().atStartOfDay(ZoneId.of("Z")).toOffsetDateTime();

    OffsetDateTime startDate = shimDataRequest.getStartDateTime() == null ? today.minusDays(1)
            : shimDataRequest.getStartDateTime();

    OffsetDateTime endDate = shimDataRequest.getEndDateTime() == null ? today.plusDays(1)
            : shimDataRequest.getEndDateTime();

    OffsetDateTime currentDate = startDate;

    if (fitbitDataType.equals(FitbitDataType.WEIGHT)) {
        return getRangeData(startDate, endDate, fitbitDataType, shimDataRequest.getNormalize(), accessToken,
                tokenSecret);
    } else {
        /**
         * Fitbit's API limits you to making a request for each given day
         * of data. Thus we make a request for each day in the submitted time
         * range and then aggregate the response based on the normalization parameter.
         */
        List<ShimDataResponse> dayResponses = new ArrayList<>();

        while (currentDate.toLocalDate().isBefore(endDate.toLocalDate())
                || currentDate.toLocalDate().isEqual(endDate.toLocalDate())) {

            dayResponses.add(getDaysData(currentDate, fitbitDataType, shimDataRequest.getNormalize(),
                    accessToken, tokenSecret));
            currentDate = currentDate.plusDays(1);
        }

        ShimDataResponse shimDataResponse = shimDataRequest.getNormalize() ? aggregateNormalized(dayResponses)
                : aggregateIntoList(dayResponses);

        return shimDataResponse;
    }
}

From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java

private JPanel createPanel() {
    EnumSet<AccountType> set = EnumSet.of(AccountType.INCOME, AccountType.EXPENSE);

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));

    startField = new DatePanel();

    endField = new DatePanel();

    showEmptyCheck = new JCheckBox(rb.getString("Label.ShowEmptyAccounts"));

    showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));

    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);

    combo = AccountListComboBox.getParentTypeInstance(engine.getRootAccount(), set);

    final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now()).minusYears(1);

    long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));

    startField.setDate(DateUtils.asLocalDate(start));

    currentAccount = combo.getSelectedAccount();
    JFreeChart chart = createPieChart(currentAccount);
    chartPanel = new ChartPanel(chart, true, true, true, false, true);
    //                         (chart, properties, save, print, zoom, tooltips)

    FormLayout layout = new FormLayout("p, 4dlu, 70dlu, 8dlu, p, 4dlu, 70dlu, 8dlu, p, 4dlu:g, left:p",
            "f:d, 3dlu, f:d, 6dlu, f:p:g");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    layout.setRowGroups(new int[][] { { 1, 3 } });

    builder.append(combo, 9);/*from  w w w .j  a v  a  2 s. c o  m*/
    builder.append(showEmptyCheck);
    builder.nextLine();

    builder.nextLine();

    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.append(refreshButton);

    builder.append(showPercentCheck);
    builder.nextLine();
    builder.nextLine();

    builder.append(chartPanel, 11);

    JPanel panel = builder.getPanel();

    combo.addActionListener(e -> {
        setCurrentAccount(combo.getSelectedAccount());
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });

    refreshButton.addActionListener(e -> {
        setCurrentAccount(currentAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });

    showEmptyCheck.addActionListener(e -> setCurrentAccount(currentAccount));

    showPercentCheck.addActionListener(e -> ((PiePlot) chartPanel.getChart().getPlot())
            .setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels));

    ChartMouseListener mouseListener = new ChartMouseListener() {

        @Override
        public void chartMouseClicked(final ChartMouseEvent event) {
            MouseEvent me = event.getTrigger();
            if (me.getID() == MouseEvent.MOUSE_CLICKED && me.getClickCount() == 1) {
                try {
                    ChartEntity entity = event.getEntity();
                    // expand sections if interesting, back out if in nothing
                    if (entity instanceof PieSectionEntity) {
                        Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
                        if (a.getChildCount() > 0) {
                            setCurrentAccount(a);
                        }
                    } else if (entity == null) {
                        Account parent = currentAccount;
                        if (parent == null) {
                            return;
                        }
                        parent = parent.getParent();
                        if (parent == null || parent instanceof RootAccount) {
                            return;
                        }
                        setCurrentAccount(parent);
                    }
                } catch (final Exception e) {
                    Logger.getLogger(IncomeExpensePieChart.class.getName()).log(Level.SEVERE,
                            e.getLocalizedMessage(), e);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            setChartCursor(chartPanel, event.getEntity(), event.getTrigger().getPoint());
        }
    };

    chartPanel.addChartMouseListener(mouseListener);

    return panel;
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testEventGeneration() {
    List<TicketCategoryModification> categories = Collections.singletonList(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));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();//w  w w . ja va 2  s  .  c om
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, tickets.size());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}

From source file:com.bdb.weather.display.freeplot.FreePlot.java

/**
 * Create the panel that allows the user to select the date ranges
 * /*from w w  w.  j a  v a  2s.  c  om*/
 * @return The JavaFX Node
 */
private Node createDataRangeSelectionPanel() {
    LocalDate start = LocalDate.now();
    LocalDate end = LocalDate.now();

    dataRangePanel = new DataRangeSelectionPanel(start, end);
    return dataRangePanel;
}

From source file:newcontroller.handler.impl.DefaultRequestTest.java

@Test
public void testPutAndGet() throws Exception {
    HttpServletRequest request = MockMvcRequestBuilders.get("/").buildRequest(new MockServletContext());
    Request req = new DefaultRequest(request);
    LocalDate now = LocalDate.now();
    req.put("foo", 100).put("bar", "hoge").put("piyo", now);

    assertThat(req.get("foo", Integer.class), is(100));
    assertThat(req.get("bar", String.class), is("hoge"));
    assertThat(req.get("piyo", LocalDate.class), is(now));
}

From source file:alfio.manager.AdminReservationManagerIntegrationTest.java

@Test
public void testReserveFromExistingCategoryNotEnoughSeatsNotBounded() throws Exception {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    performExistingCategoryTest(categories, false, Collections.singletonList(1), false, true, 0,
            AVAILABLE_SEATS);/*www .ja v a 2 s  .  com*/
}