Example usage for java.time YearMonth atDay

List of usage examples for java.time YearMonth atDay

Introduction

In this page you can find the example usage for java.time YearMonth atDay.

Prototype

public LocalDate atDay(int dayOfMonth) 

Source Link

Document

Combines this year-month with a day-of-month to create a LocalDate .

Usage

From source file:Main.java

public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    LocalDate l = y.atDay(2);
    System.out.println(l);//from  w  w  w  .  ja va  2  s . c  om

}

From source file:Main.java

private static LocalDate firstDayOfCalendar(YearMonth month) {
    DayOfWeek FIRST_DAY_OF_WEEK = DayOfWeek.MONDAY;
    return month.atDay(1).with(FIRST_DAY_OF_WEEK);
}

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

@Override
@Transactional(readOnly = true)//w  w  w .  j  a  v a 2 s.  c  o  m
public PlanningDto getDateOuvert(final YearMonth anneeMois, final Famille famille) throws TechnicalException {
    final Date startDate = Date.from(Instant.from(anneeMois.atDay(1).atStartOfDay(ZoneId.systemDefault())));
    final Date endDate = Date.from(Instant.from(anneeMois.atEndOfMonth().atStartOfDay(ZoneId.systemDefault())));

    final Activite activite = getCantineActivite();

    final LocalDateTime heureH = LocalDateTime.now();
    final List<Inscription> icts = this.ictRepository.findByActiviteAndFamille(activite, famille);

    final PlanningDto planning = new PlanningDto();

    icts.forEach(ict -> {
        planning.getHeaders().add(ict.getIndividu().getPrenom());
        final List<Consommation> consos = this.consommationRepository
                .findByFamilleInscriptionActiviteUniteEtatsPeriode(famille, activite, ict.getGroupe(),
                        Arrays.asList("reservation"), startDate, endDate);
        final List<Ouverture> ouvertures = this.ouvertureRepository.findByActiviteAndGroupeAndPeriode(activite,
                ict.getGroupe(), startDate, endDate);
        ouvertures.forEach(o -> {
            final LocalDate date = LocalDate.from(((java.sql.Date) o.getDate()).toLocalDate());
            final LocalDateTime heureResa = this.getLimiteResaCantine(date);
            final LigneDto ligne = planning.getOrCreateLigne(date);
            final CaseDto c = new CaseDto();
            c.setDate(date);
            c.setIndividu(ict.getIndividu());
            c.setActivite(o.getActivite());
            c.setUnite(o.getUnite());
            c.setReservable(heureResa.isAfter(heureH));
            final Optional<Consommation> cOpt = consos.stream().filter(conso -> {
                final LocalDate dateConso = LocalDate.from(((java.sql.Date) conso.getDate()).toLocalDate());
                return dateConso.equals(date);
            }).findAny();
            c.setReserve(cOpt.isPresent());
            ligne.getCases().add(c);
        });
    });

    return planning;
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java

@Override
public Collection<Collection<Object>> analyze(final Collection<String> parameter) {
    YearMonth requestedMonth = YearMonth.now();
    if (parameter.size() > 0) {
        requestedMonth = YearMonth.parse(Iterables.get(parameter, 0));
    }//from www.j ava2 s  .  com
    Collection<Collection<Object>> result = Lists.newArrayList();
    result.add(Arrays.asList("Work Day", "Starttime", "Endtime", "Presence", "Worktime", "Breaktime",
            "Overtime", "Comment"));
    Duration overtime = Duration.ZERO;
    LocalDate currentday = requestedMonth.atDay(1);
    while (!currentday.isAfter(requestedMonth.atEndOfMonth())) {
        Collection<Booking> currentBookings = getBookingsForDay(currentday);
        if (hasCompleteBookings(currentBookings)) {
            String day = currentday.format(DateTimeFormatter.ISO_LOCAL_DATE);
            LocalTime starttime = Iterables.getFirst(currentBookings, null).getStarttime();
            LocalTime endtime = Iterables.getLast(currentBookings).getEndtime();
            Duration presence = calculatePresence(starttime, endtime);
            Duration worktime = calculateWorktime(currentBookings);
            Duration breaktime = calculateBreaktime(presence, worktime);
            Duration currentOvertime = calculateOvertime(worktime, currentday);
            overtime = overtime.plus(currentOvertime);
            result.add(Arrays.asList(day, starttime.format(DateTimeFormatter.ofPattern("HH:mm")),
                    endtime.format(DateTimeFormatter.ofPattern("HH:mm")), formatDuration(presence),
                    formatDuration(worktime), formatDuration(breaktime), formatDuration(overtime),
                    validate(worktime, breaktime)));
        }
        currentday = currentday.plusDays(1);
    }
    return result;
}

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

private Period in(YearMonth yearMonth) {
    return Period.between(yearMonth.atDay(1).atStartOfDay().atOffset(ZoneOffset.UTC),
            yearMonth.atEndOfMonth().plusDays(1).atStartOfDay().minusMinutes(1).atOffset(ZoneOffset.UTC));
}

From source file:org.tightblog.util.Utilities.java

/**
 * Parse date as either 6-char or 8-char format.  Use current date if date not provided
 * in URL (e.g., a permalink), more than 30 days in the future, or not valid
 *//*from w ww  .jav  a2 s  .com*/
public static LocalDate parseURLDate(String dateString) {
    LocalDate ret = null;

    try {
        if (StringUtils.isNumeric(dateString)) {
            if (dateString.length() == 8) {
                ret = LocalDate.parse(dateString, Utilities.YMD_FORMATTER);
            } else if (dateString.length() == 6) {
                YearMonth tmp = YearMonth.parse(dateString, Utilities.YM_FORMATTER);
                ret = tmp.atDay(1);
            }
        }
    } catch (DateTimeParseException ignored) {
        ret = null;
    }

    // make sure the requested date is not more than a month in the future
    if (ret == null || ret.isAfter(LocalDate.now().plusDays(30))) {
        ret = LocalDate.now();
    }

    return ret;
}