Example usage for java.time LocalDate of

List of usage examples for java.time LocalDate of

Introduction

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

Prototype

public static LocalDate of(int year, int month, int dayOfMonth) 

Source Link

Document

Obtains an instance of LocalDate from a year, month and day.

Usage

From source file:ca.phon.session.io.xml.v12.XMLSessionReader_v12.java

private Participant copyParticipant(SessionFactory factory, ParticipantType pt, LocalDate sessionDate) {
    final Participant retVal = factory.createParticipant();

    retVal.setId(pt.getId());/*from w  w w  .j a v a2 s  . c o m*/
    retVal.setName(pt.getName());

    final XMLGregorianCalendar bday = pt.getBirthday();
    if (bday != null) {
        final LocalDate bdt = LocalDate.of(bday.getYear(), bday.getMonth(), bday.getDay());
        retVal.setBirthDate(bdt);

        // calculate age up to the session date
        final Period period = Period.between(bdt, sessionDate);
        retVal.setAgeTo(period);
    }

    final Duration ageDuration = pt.getAge();
    if (ageDuration != null) {
        // convert to period
        final Period age = Period.of(ageDuration.getYears(), ageDuration.getMonths(), ageDuration.getDays());
        retVal.setAge(age);
    }

    retVal.setEducation(pt.getEducation());
    retVal.setGroup(pt.getGroup());

    String langs = "";
    for (String lang : pt.getLanguage())
        langs += (langs.length() > 0 ? ", " : "") + lang;
    retVal.setLanguage(langs);

    if (pt.getSex() == SexType.MALE)
        retVal.setSex(Sex.MALE);
    else if (pt.getSex() == SexType.FEMALE)
        retVal.setSex(Sex.FEMALE);
    else
        retVal.setSex(Sex.UNSPECIFIED);

    ParticipantRole prole = ParticipantRole.fromString(pt.getRole());
    if (prole == null)
        prole = ParticipantRole.TARGET_CHILD;
    retVal.setRole(prole);

    retVal.setSES(pt.getSES());

    return retVal;
}

From source file:de.speexx.jira.jan.command.transition.IssueTransitionFetcher.java

LocalDate createLocalDate(final DateTime dt) {
    final int year = dt.getYear();
    final int month = dt.getMonthOfYear();
    final int day = dt.getDayOfMonth();
    return LocalDate.of(year, month, day);
}

From source file:de.jfachwert.rechnung.Rechnungsmonat.java

/**
 * Liefert den ersten Tag eines Rechnungsmonats.
 * /*  www.j ava2  s  .  c om*/
 * @return z.B. 1.3.2018
 * @since 0.6
 */
public LocalDate ersterTag() {
    return LocalDate.of(getJahr(), getMonat(), 1);
}

From source file:org.openlmis.fulfillment.service.OrderCsvHelperTest.java

private ProcessingPeriodDto createPeriod() {
    ProcessingPeriodDto period = new ProcessingPeriodDto();
    period.setName("periodName");
    period.setStartDate(LocalDate.of(2016, Month.JANUARY, 1));

    return period;
}

From source file:org.tightblog.rendering.generators.WeblogEntryListGeneratorTest.java

@Test
public void getChronoPager() {
    String dateString = "20180110";
    String catName = "stamps";
    String tag = "airmail";
    int pageNum = 2;
    int maxEntries = 3;

    Map<LocalDate, List<WeblogEntry>> entryMap = createSampleEntriesMap();

    when(mockWEM.getDateToWeblogEntryMap(any())).thenReturn(entryMap);
    when(mockUrlService.getWeblogCollectionURL(weblog, catName, dateString, tag, pageNum - 1))
            .thenReturn("nextUrl");
    when(mockUrlService.getWeblogCollectionURL(weblog, catName, dateString, tag, pageNum + 1))
            .thenReturn("prevUrl");

    WeblogEntryListData data = generator.getChronoPager(weblog, dateString, catName, tag, pageNum, maxEntries,
            false);/*  w  w w.  ja v  a  2 s . c  om*/

    Map<LocalDate, List<WeblogEntry>> results = data.getEntries();
    assertEquals(2, results.size());
    assertEquals(2, results.get(nowLD).size());
    assertEquals(1, results.get(yesterdayLD).size());
    assertEquals("day1story1", results.get(nowLD).get(0).getAnchor());
    assertEquals("day1story2", results.get(nowLD).get(1).getAnchor());
    assertEquals("day2story1", results.get(yesterdayLD).get(0).getAnchor());
    assertEquals("prevUrl", data.getPrevLink());
    assertNotNull(data.getPrevLabel());
    assertEquals("nextUrl", data.getNextLink());
    assertNotNull(data.getNextLabel());

    // test wesc correctly populated
    ArgumentCaptor<WeblogEntrySearchCriteria> captor = ArgumentCaptor.forClass(WeblogEntrySearchCriteria.class);
    verify(mockWEM).getDateToWeblogEntryMap(captor.capture());
    WeblogEntrySearchCriteria wesc = captor.getValue();
    assertEquals(weblog, wesc.getWeblog());
    assertEquals(LocalDate.of(2018, 1, 10).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(),
            wesc.getStartDate());
    assertEquals(
            LocalDate.of(2018, 1, 11).atStartOfDay().minusNanos(1).atZone(ZoneId.systemDefault()).toInstant(),
            wesc.getEndDate());
    assertEquals("stamps", wesc.getCategoryName());
    assertEquals("airmail", wesc.getTag());
    assertEquals(pageNum * maxEntries, wesc.getOffset());
    assertEquals(WeblogEntry.PubStatus.PUBLISHED, wesc.getStatus());
    assertEquals(maxEntries + 1, wesc.getMaxResults());

    // test maxEntries honored
    data = generator.getChronoPager(weblog, dateString, catName, tag, pageNum, 1, false);
    assertEquals(1, data.getEntries().size());

    data = generator.getChronoPager(weblog, dateString, catName, tag, pageNum, 0, false);
    assertEquals(0, data.getEntries().size());

    // another wesc test:
    // if sitewide, no weblog
    // if no datestring, no start or end
    // page 0, so no next links
    // moreResults = false so no prev links
    Mockito.clearInvocations(mockWEM);
    dateString = null;
    pageNum = 0;
    maxEntries = 10;
    data = generator.getChronoPager(weblog, dateString, catName, tag, pageNum, maxEntries, true);
    verify(mockWEM).getDateToWeblogEntryMap(captor.capture());
    wesc = captor.getValue();
    assertNull(wesc.getWeblog());
    assertNull(wesc.getStartDate());
    assertNull(wesc.getEndDate());
    assertNull(data.getPrevLink());
    assertNull(data.getPrevLabel());
    assertNull(data.getNextLink());
    assertNull(data.getNextLabel());

    // check month format (YYYYMM) correctly processed in search criteria
    Mockito.clearInvocations(mockWEM);
    dateString = "201805";
    generator.getChronoPager(weblog, dateString, catName, tag, pageNum, maxEntries, true);
    verify(mockWEM).getDateToWeblogEntryMap(captor.capture());
    wesc = captor.getValue();
    assertEquals(LocalDate.of(2018, 5, 1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(),
            wesc.getStartDate());
    assertEquals(
            LocalDate.of(2018, 6, 1).atStartOfDay().minusNanos(1).atZone(ZoneId.systemDefault()).toInstant(),
            wesc.getEndDate());

    // check invalid length of date format (YYYYMMD) ignored in search criteria
    Mockito.clearInvocations(mockWEM);
    dateString = "2018051";
    generator.getChronoPager(weblog, dateString, catName, tag, pageNum, maxEntries, true);
    verify(mockWEM).getDateToWeblogEntryMap(captor.capture());
    wesc = captor.getValue();
    assertNull(wesc.getStartDate());
    assertNull(wesc.getEndDate());
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void testGetAllReservations() {

    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    assertTrue(reservationManager.findAllReservations().isEmpty());

    Reservation r1 = setReservation(1, 1, checkin, checkout, reservationdate);
    Reservation r2 = setReservation(2, 2, checkin.plusDays(1), checkout, reservationdate.plusDays(2));

    reservationManager.createReservation(r1);
    reservationManager.createReservation(r2);

    List<Reservation> expected = Arrays.asList(r1, r2);
    List<Reservation> actual = reservationManager.findAllReservations();

    Collections.sort(actual, idComparator);
    Collections.sort(expected, idComparator);

    assertEquals("saved and retrieved reservations differ", expected, actual);
    assertDeepEquals(expected, actual);/*from   w w  w  .  j  av  a2s. c om*/
}

From source file:daylightchart.daylightchart.calculation.RiseSetUtility.java

/**
 * Generate a year's worth of dates//from   ww w  .ja  v  a 2  s .  c o  m
 *
 * @return All the dates for the year
 */
private static List<LocalDate> getYearsDates(final int year) {
    final List<LocalDate> dates = new ArrayList<LocalDate>();
    LocalDate date = LocalDate.of(year, 1, 1);
    do {
        dates.add(date);
        date = date.plusDays(1);
    } while (!(date.getMonthValue() == 1 && date.getDayOfMonth() == 1));
    return dates;
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void TestdeleteRoom() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Reservation r1 = setReservation(1, 1, checkin, checkout, reservationdate);
    Reservation r2 = setReservation(2, 2, checkin.plusDays(1), checkout, reservationdate.plusDays(2));
    reservationManager.createReservation(r1);
    reservationManager.createReservation(r2);

    assertNotNull(reservationManager.findReservation(r1.getReservationId()));
    assertNotNull(reservationManager.findReservation(r2.getReservationId()));

    reservationManager.deleteReservation(r1);

    assertNull(reservationManager.findReservation(r1.getReservationId()));
    assertNotNull(reservationManager.findReservation(r2.getReservationId()));
}

From source file:ch.algotrader.service.tt.TTFixReferenceDataServiceImpl.java

private void retrieveFutures(final FutureFamily securityFamily, final List<TTSecurityDefVO> securityDefs) {

    // get all current futures
    List<Future> allFutures = this.futureDao.findBySecurityFamily(securityFamily.getId());
    Map<String, Future> mapByTtid = allFutures.stream().filter(e -> e.getTtid() != null)
            .collect(Collectors.toMap(e -> e.getTtid(), e -> e));
    Map<String, Future> mapBySymbol = allFutures.stream().collect(Collectors.toMap(e -> e.getSymbol(), e -> e));

    for (TTSecurityDefVO securityDef : securityDefs) {

        String type = securityDef.getType();
        if (!type.equalsIgnoreCase("FUT")) {
            throw new ServiceException("Unexpected security definition type for future: " + type);
        }//www .java  2  s  . co  m
        String id = securityDef.getId();
        if (!mapByTtid.containsKey(id)) {

            LocalDate maturityDate = securityDef.getMaturityDate();
            LocalDate expiration = maturityDate.withDayOfMonth(1);

            // IPE e-Brent has to be handled as a special case as it happens to have multiple contracts
            // with the same expiration month
            String symbol;
            if ("ICE_IPE".equalsIgnoreCase(securityDef.getExchange()) && securityDef.getAltSymbol() != null) {
                String altSymbol = securityDef.getAltSymbol();
                if (altSymbol.startsWith("Q") || altSymbol.startsWith("Cal")) {
                    continue;
                } else {
                    try {
                        TemporalAccessor parsed = ICE_IPE_SYMBOL.parse(altSymbol);
                        int year = parsed.get(ChronoField.YEAR);
                        int month = parsed.get(ChronoField.MONTH_OF_YEAR);
                        expiration = LocalDate.of(year, month, 1);
                        symbol = FutureSymbol.getSymbol(securityFamily, expiration,
                                this.commonConfig.getFutureSymbolPattern());
                    } catch (DateTimeParseException ex) {
                        throw new ServiceException(
                                "Unable to parse IPE e-Brent expiration month / year: " + altSymbol, ex);
                    }
                }
            } else {
                symbol = FutureSymbol.getSymbol(securityFamily, maturityDate,
                        this.commonConfig.getFutureSymbolPattern());
            }
            if (!mapBySymbol.containsKey(symbol)) {
                Future future = Future.Factory.newInstance();
                String isin = securityFamily.getIsinRoot() != null
                        ? FutureSymbol.getIsin(securityFamily, maturityDate)
                        : null;
                String ric = securityFamily.getRicRoot() != null
                        ? FutureSymbol.getRic(securityFamily, maturityDate)
                        : null;

                future.setSymbol(symbol);
                future.setIsin(isin);
                future.setRic(ric);
                future.setTtid(id);
                future.setExpiration(DateTimeLegacy.toLocalDate(expiration));
                future.setMonthYear(DateTimePatterns.MONTH_YEAR.format(maturityDate));
                future.setSecurityFamily(securityFamily);
                future.setUnderlying(securityFamily.getUnderlying());

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Creating future based on TT definition: {} {}", securityDef.getSymbol(),
                            securityDef.getMaturityDate());
                }
                this.futureDao.save(future);
            } else {
                Future future = mapBySymbol.get(symbol);
                future.setTtid(id);

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Updating future based on TT definition: {} {}", securityDef.getSymbol(),
                            securityDef.getMaturityDate());
                }
            }
        }
    }
}

From source file:com.romeikat.datamessie.core.base.query.DocumentFilterSettingsQueryTest.java

@Test
public void list_documentsByFromDate() {
    final DocumentsFilterSettings dfs = new DocumentsFilterSettings().setFromDate(LocalDate.of(2015, 10, 1));
    final DocumentFilterSettingsQuery<Document> query = new DocumentFilterSettingsQuery<Document>(dfs,
            Document.class, sharedBeanProvider);

    final List<Document> result = query.listObjects(sessionProvider.getStatelessSession());
    assertEquals(4, result.size());//from   w  w  w  . j  ava 2 s.c  o  m

    dbSetupTracker.skipNextLaunch();
}