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:example.complete.Customer.java

Customer(String firstname, String lastname, LocalDate birthday) {

    Assert.hasText(firstname, "Firstname must not be null or empty!");
    Assert.hasText(lastname, "Lastname must not be null or empty!");
    Assert.isTrue(birthday.isBefore(LocalDate.now()), "Date of birth must be in the past!");

    this.firstname = firstname;
    this.lastname = lastname;
    this.birthday = birthday;
}

From source file:com.github.drbookings.LocalDates.java

public static Pair<LocalDate, LocalDate> getFirstAndLastDayOfMonth(final int month) {
    final int year = LocalDate.now().getYear();
    final LocalDate firstDay = LocalDate.of(year, month, 1);
    final LocalDate lastDay = getLastDayOfMonth(firstDay);
    return new ImmutablePair<>(firstDay, lastDay);
}

From source file:org.jc.exercicios.colecoes.eqhc.Associado.java

public int idade() {
    return LocalDate.now().getYear() - this.nascimento.getYear();
}

From source file:fi.helsinki.opintoni.service.portfolio.WorkExperienceServiceTest.java

@Test
public void thatWorkExperienceIsSaved() {
    Long portfolioId = 3L;/*from  w w  w. ja v  a  2  s  . c om*/

    WorkExperienceDto workExperienceDto = new WorkExperienceDto();
    workExperienceDto.jobTitle = "Jobtitle";
    workExperienceDto.employer = "Employer name";
    workExperienceDto.startDate = LocalDate.now();
    workExperienceDto.endDate = LocalDate.now();

    workExperienceService.insert(portfolioId, workExperienceDto);

    List<WorkExperienceDto> workExperienceDtos = workExperienceService.findByPortfolioId(portfolioId);

    WorkExperienceDto savedWorkExperienceDto = workExperienceDtos.get(0);

    assertThat(workExperienceDtos).hasSize(1);
    assertThat(savedWorkExperienceDto.jobTitle).isEqualTo(workExperienceDto.jobTitle);
    assertThat(savedWorkExperienceDto.employer).isEqualTo(workExperienceDto.employer);
    assertThat(savedWorkExperienceDto.startDate).isEqualTo(workExperienceDto.startDate);
    assertThat(savedWorkExperienceDto.endDate).isEqualTo(workExperienceDto.endDate);
}

From source file:org.jc.exercicios.colecoes.eqhc.Dependente.java

public int idade() {
    return LocalDate.now().getYear() - nascimento.getYear();
}

From source file:org.tudresden.ecatering.model.stock.Ingredient.java

protected Ingredient(String name, Money price, Quantity quantity, LocalDate expirationDate) {

    super(new Product(name, price, quantity.getMetric()), quantity);

    if (expirationDate != null)
        if (expirationDate.isBefore(LocalDate.now()))
            throw new IllegalArgumentException("expirationDate already expired");

    this.expirationDate = expirationDate;
}

From source file:org.vaadin.peholmst.samples.dddwebinar.domain.billing.InsuranceClaimService.java

public InsuranceClaim createInsuranceClaim(Appointment appointment) {
    if (insuranceClaimRepository.findByAppointment(appointment) != null) {
        throw new IllegalArgumentException("The specified appointment already has an insurance claim");
    }/*  w  w  w . jav  a2 s.c  om*/

    License license = licenseService.selectBestLicense(appointment.getProcedures(), appointment.getDoctor())
            .orElseThrow(() -> new IllegalArgumentException(
                    "The doctor is not licensed to perform all the procedures"));

    Insurance insurance = insuranceRepository.findByPatient(appointment.getPatient());
    if (insurance == null) {
        throw new IllegalArgumentException("The patient has no insurance");
    }

    InsuranceClaim claim = new InsuranceClaim(LocalDate.now(), appointment.getTotalFee(), appointment, license,
            insurance);
    return insuranceClaimRepository.saveAndFlush(claim);
}

From source file:dijalmasilva.testes.GrupoServiceTeste.java

@Before
public void init() {
    Usuario u = new Usuario();
    u.setAmigos(null);/*from   w w  w .  j av a 2  s  .  c o m*/
    u.setConta("ATIVADA");
    u.setDataDeNascimento(LocalDate.now());
    u.setEmail("teste@gmail.com");
    u.setNome("teste");
    u.setSobrenome("sobreteste");
    u.setSenha("123");
    u.setGrupos(null);
    u.setPontos(0);
    u.setFoto(null);
    Idolo i = new Idolo();
    i.setEsporte(Esporte.BASQUETE);
    i.setFoto(null);
    i.setNome("Michael Jordan");
    i.setTipo(TipoIdolo.JOGADOR);
    Usuario us = em.persist(u);
    Idolo ido = em.persist(i);
}

From source file:fi.helsinki.opintoni.service.OodiUserRoleService.java

@Cacheable(CacheConstants.IS_OPEN_UNIVERSITY_TEACHER)
public boolean isOpenUniversityTeacher(String teacherNumber) {
    List<OodiTeacherCourse> oodiTeacherCourses = oodiClient.getTeacherCourses(teacherNumber,
            DateTimeUtil.getSemesterStartDateString(LocalDate.now()));
    return oodiTeacherCourses.isEmpty() ? false
            : oodiTeacherCourses.stream().map(course -> course.basecode).allMatch(this::isOpenUniversityId);
}

From source file:org.homiefund.test.dao.TransactionDAOTest.java

@Test
public void create() {
    Transaction tx = new Transaction();
    tx.setRevoked(false);// w  w  w . j a  v  a2 s . com
    tx.setDate(LocalDate.now());
    tx.setDescription(" create tessst ");
    tx.setOwner(userDAO.getById(1L));
    tx.setTransactionType(transactionTypeDAO.getById(4L));
    tx.setAmount(BigDecimal.valueOf(30.52));
    TransactionParticipant tp1 = new TransactionParticipant();
    tp1.setParticipant(userDAO.getById(1L));
    TransactionParticipant tp2 = new TransactionParticipant();
    tp2.setParticipant(userDAO.getById(2L));
    tx.setParticipants(new ArrayList<>(Arrays.asList(tp1, tp2)));

    Assert.assertNotNull(transactionDAO.create(tx));
    Assert.assertNotNull(tx.getId());

    BigDecimal half = tx.getAmount().divide(BigDecimal.valueOf(2L), new MathContext(2, RoundingMode.HALF_UP));
    tx.getParticipants().forEach(p -> Assert.assertEquals(half, p.getAmount()));
}