Example usage for java.time LocalDate from

List of usage examples for java.time LocalDate from

Introduction

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

Prototype

public static LocalDate from(TemporalAccessor temporal) 

Source Link

Document

Obtains an instance of LocalDate from a temporal object.

Usage

From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java

public DatePicker createDateField() {
    final DatePicker retVal = new DatePicker();

    final LocalDate sessionDate = getEditor().getSession().getDate();
    if (sessionDate != null)
        retVal.setDateTime(sessionDate);

    retVal.getTextField().getDocument().addDocumentListener(new DocumentListener() {

        void dateFieldUpdate() {
            final LocalDate selectedDate = retVal.getDateTime();
            final LocalDate newDate = LocalDate.from(selectedDate);

            final SessionDateEdit edit = new SessionDateEdit(getEditor(), newDate,
                    getEditor().getSession().getDate());
            edit.setSource(dateField);/*from   w w  w  .  ja v a2 s  . co m*/
            getEditor().getUndoSupport().postEdit(edit);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            if (!dateField.isValueAdjusing())
                dateFieldUpdate();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            if (!dateField.isValueAdjusing())
                dateFieldUpdate();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {

        }

    });
    return retVal;
}

From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java

@Override
@Transactional(readOnly = true)/*ww  w .ja v  a2s .  c  o  m*/
public List<DayOfWeek> getJourOuvertCantine(final LocalDate startDate, final Famille famille)
        throws TechnicalException {
    final List<DayOfWeek> jours = new ArrayList<>();
    final Activite activite = getCantineActivite();
    final List<Inscription> icts = this.ictRepository.findByActiviteAndFamille(activite, famille);
    icts.forEach(ict -> {
        final List<Ouverture> ouvertures = this.ouvertureRepository.findByActiviteAndGroupeAndDateDebut(
                activite, ict.getGroupe(),
                Date.from(Instant.from(startDate.atStartOfDay(ZoneId.systemDefault()))));
        ouvertures.forEach(o -> {
            final LocalDate date = LocalDate.from(((java.sql.Date) o.getDate()).toLocalDate());
            if (!jours.contains(date.getDayOfWeek())) {
                jours.add(date.getDayOfWeek());
            }
        });
    });

    return jours;
}

From source file:msi.gama.util.GamaDate.java

@getter("leap")
public boolean getIsLeap() {
    return LocalDate.from(internal).isLeapYear();
}

From source file:msi.gama.util.GamaDate.java

@getter("days_in_month")
public int getDaysMonth() {
    return LocalDate.from(internal).lengthOfMonth();
}

From source file:msi.gama.util.GamaDate.java

@getter("days_in_year")
public int getDaysInYear() {
    return LocalDate.from(internal).lengthOfYear();
}

From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java

private void updateSessionDate() {
    final SessionEditor editor = getEditor();
    final Session session = editor.getDataModel().getSession();

    final LocalDate currentDate = session.getDate();
    final LocalDate newDate = LocalDate.from(dateField.getDateTime());

    if (!currentDate.isEqual(newDate)) {
        final SessionDateEdit edit = new SessionDateEdit(getEditor(), newDate, currentDate);
        edit.setSource(dateField);//from w w w. ja v  a 2 s .  com
        editor.getUndoSupport().postEdit(edit);
    }

}

From source file:com.github.aptd.simulation.datamodel.CXMLReader.java

/**
 * create the train list//from   w w  w. j a  v  a  2s.  c o  m
 *
 * @param p_network network component
 * @param p_agents map with agent asl scripts
 * @param p_factory factory
 * @return unmodifiable map with trains
 */
private static Pair<Map<String, ITrain<?>>, Map<String, IDoor<?>>> train(final Network p_network,
        final Map<String, String> p_agents, final IFactory p_factory, final ITime p_time,
        final double p_minfreetimetoclose) {
    final String l_dooragent = IStatefulElement.getDefaultAsl("door");
    final Map<String, IElement.IGenerator<ITrain<?>>> l_generators = new ConcurrentHashMap<>();
    final Set<IAction> l_actions = CCommon.actionsFromPackage().collect(Collectors.toSet());
    final IElement.IGenerator<IDoor<?>> l_doorgenerator = doorgenerator(p_factory, l_dooragent, l_actions,
            p_time);
    final Map<String, AtomicLong> l_doorcount = Collections.synchronizedMap(new HashMap<>());
    final Map<String, IDoor<?>> l_doors = Collections.synchronizedMap(new HashMap<>());
    return new ImmutablePair<>(
            Collections.<String, ITrain<?>>unmodifiableMap(
                    p_network.getTimetable().getTrains().getTrain().parallelStream()
                            .filter(i -> hasagentname(i.getAny3())).map(i -> agentname(i, i.getAny3()))
                            .map(i -> l_generators
                                    .computeIfAbsent(i.getRight(),
                                            a -> traingenerator(p_factory, p_agents.get(i.getRight()),
                                                    l_actions, p_time))
                                    .generatesingle(i.getLeft().getId(),
                                            i.getLeft().getTrainPartSequence().stream().flatMap(ref -> {
                                                // @todo support multiple train parts
                                                final EOcpTT[] l_tts = ((ETrainPart) ref.getTrainPartRef()
                                                        .get(0).getRef()).getOcpsTT().getOcpTT()
                                                                .toArray(new EOcpTT[0]);
                                                final CTrain.CTimetableEntry[] l_entries = new CTrain.CTimetableEntry[l_tts.length];
                                                for (int j = 0; j < l_tts.length; j++) {
                                                    final EArrivalDepartureTimes l_times = l_tts[j].getTimes()
                                                            .stream()
                                                            .filter(t -> t.getScope()
                                                                    .equalsIgnoreCase("published"))
                                                            .findAny().orElseThrow(() -> new CSemanticException(
                                                                    "missing published times"));
                                                    l_entries[j] = new CTrain.CTimetableEntry(
                                                            j < 1 ? 0.0
                                                                    : ((ETrack) l_tts[j - 1].getSectionTT()
                                                                            .getTrackRef().get(0).getRef())
                                                                                    .getTrackTopology()
                                                                                    .getTrackEnd().getPos()
                                                                                    .doubleValue(),
                                                            ((EOcp) l_tts[j].getOcpRef()).getId(),
                                                            l_tts[j].getStopDescription().getOtherAttributes()
                                                                    .getOrDefault(PLATFORM_REF_ATTRIBUTE, null),
                                                            l_times.getArrival() == null ? null
                                                                    : l_times.getArrival().toGregorianCalendar()
                                                                            .toZonedDateTime()
                                                                            .with(LocalDate.from(p_time
                                                                                    .current()
                                                                                    .atZone(ZoneId
                                                                                            .systemDefault())))
                                                                            .toInstant(),
                                                            l_times.getDeparture() == null ? null
                                                                    : l_times.getDeparture()
                                                                            .toGregorianCalendar()
                                                                            .toZonedDateTime()
                                                                            .with(LocalDate.from(p_time
                                                                                    .current()
                                                                                    .atZone(ZoneId
                                                                                            .systemDefault())))
                                                                            .toInstant());
                                                }
                                                return Arrays.stream(l_entries);
                                            }), i.getLeft().getTrainPartSequence().stream()
                                                    // @todo support multiple train parts
                                                    .map(s -> (ETrainPart) s.getTrainPartRef().get(0).getRef())
                                                    .map(p -> (EFormation) p.getFormationTT().getFormationRef())
                                                    .flatMap(f -> f.getTrainOrder().getVehicleRef().stream())
                                                    .map(r -> new ImmutablePair<BigInteger, TDoors>(
                                                            r.getVehicleCount(),
                                                            ((EVehicle) r.getVehicleRef()).getWagon()
                                                                    .getPassenger().getDoors()))
                                                    .flatMap(v -> IntStream
                                                            .range(0,
                                                                    v.getLeft().intValue() * v.getRight()
                                                                            .getNumber().intValue())
                                                            .mapToObj(j -> l_doors.computeIfAbsent("door-"
                                                                    + i.getLeft().getId() + "-"
                                                                    + l_doorcount
                                                                            .computeIfAbsent(i.getLeft()
                                                                                    .getId(),
                                                                                    id -> new AtomicLong(1L))
                                                                            .getAndIncrement(),
                                                                    id -> l_doorgenerator.generatesingle(id,
                                                                            i.getLeft().getId(),
                                                                            v.getRight().getEntranceWidth()
                                                                                    .doubleValue()
                                                                                    / v.getRight().getNumber()
                                                                                            .longValue(),
                                                                            p_minfreetimetoclose))))
                                                    .collect(Collectors.toList())))
                            .collect(Collectors.toMap(IElement::id, i -> i))),
            l_doors);
}

From source file:org.nuxeo.apidoc.browse.Distribution.java

protected Map<String, Serializable> readFormData(FormData formData) {
    Map<String, Serializable> properties = new HashMap<>();

    // Release date
    String released = formData.getString("released");
    if (StringUtils.isNotBlank(released)) {
        LocalDate date = LocalDate.parse(released);
        Instant instant = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
        properties.put(PROP_RELEASED, Date.from(instant));
    }/* w  w  w .j  a  v a2s.  com*/

    return properties;
}

From source file:org.silverpeas.core.calendar.Recurrence.java

private Temporal computeEndDate() {
    Temporal date = this.getStartDate();
    if (getRecurrenceCount() == 1) {
        return date;
    }/*from   ww  w  .  j  a  v a  2 s. c  o  m*/
    final long interval = (long) getRecurrenceCount()
            * (getFrequency().getInterval() >= 1 ? getFrequency().getInterval() : 1);
    date = date.plus(interval, getFrequency().getUnit().toChronoUnit());
    boolean firstDayOfWeekSet = false;
    for (DayOfWeekOccurrence dayOfWeek : daysOfWeek) {
        Temporal current = date.with(dayOfWeek.dayOfWeek());
        if (getFrequency().isMonthly()) {
            current = computeDateForMonthlyFrequencyFrom(current, dayOfWeek);
        } else if (getFrequency().isYearly()) {
            current = computeDateForYearlyFrequencyFrom(current, dayOfWeek);
        }

        if (!firstDayOfWeekSet || LocalDate.from(current).isAfter(LocalDate.from(date))) {
            date = current;
            firstDayOfWeekSet = true;
        }
    }
    return date;
}

From source file:org.silverpeas.core.date.Period.java

/**
 * Creates a new period of time between the two specified non null date or datetime.
 * If date parameters are instances of {@link LocalDate}, take a look at method
 * {@link #between(LocalDate, LocalDate)}.
 * If date parameters are instances of {@link OffsetDateTime}, take a look at method
 * {@link #between(OffsetDateTime, OffsetDateTime)}.
 * @param start the start of the period. It defines the inclusive date or datetime at which the
 * period starts./*  www. j  a  va 2  s  .  c  om*/
 * @param end the end day of the period. It defines the exclusive date or the exclusive datetime
 * at which the period ends. The end date must be the same or after the start date. An end date
 * equal to the start date means the period is spanning all the day; it is equivalent to an end
 * date being one day after the start date.
 * @return the period of days between the two specified dates.
 * @throws IllegalArgumentException if date parameters are not both {@link LocalDate} or
 * {@link OffsetDateTime} instances.
 */
public static Period between(java.time.temporal.Temporal start, java.time.temporal.Temporal end) {
    if (start instanceof LocalDate && end instanceof LocalDate) {
        return between(LocalDate.from(start), LocalDate.from(end));
    } else if (start instanceof OffsetDateTime && end instanceof OffsetDateTime) {
        return between(OffsetDateTime.from(start), OffsetDateTime.from(end));
    } else {
        throw new IllegalArgumentException(
                "Temporal parameters must be either of type LocalDate or OffsetDateTime");
    }
}