List of usage examples for java.time LocalDate getDayOfWeek
public DayOfWeek getDayOfWeek()
From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java
private boolean isWeekDay(final LocalDate day) { return !(day.getDayOfWeek() == DayOfWeek.SATURDAY || day.getDayOfWeek() == DayOfWeek.SUNDAY); }
From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingServiceTypeCalendar.java
private void parseCalendarFile(final Reader calendarReader, final Multimap<LocalDate, String> serviceTypesMap) throws IOException { final CSVParser calendarParser = new CSVParser(calendarReader, CSVFormat.DEFAULT.withHeader()); final List<CSVRecord> calendarRecords = calendarParser.getRecords(); LocalDate earliestDate = null; LocalDate latestDate = null;// w w w .j a v a 2 s . c o m for (final CSVRecord record : calendarRecords) { final String serviceType = record.get("service_id"); final LocalDate start = LocalDate.parse(record.get("start_date"), DateTimeFormatter.BASIC_ISO_DATE); if (earliestDate == null || start.isBefore(earliestDate)) { earliestDate = start; } final LocalDate end = LocalDate.parse(record.get("end_date"), DateTimeFormatter.BASIC_ISO_DATE); if (latestDate == null || end.isAfter(latestDate)) { latestDate = end; } final EnumSet<DayOfWeek> daysOfWeek = EnumSet.noneOf(DayOfWeek.class); if (record.get("monday").equals("1")) { daysOfWeek.add(DayOfWeek.MONDAY); } if (record.get("tuesday").equals("1")) { daysOfWeek.add(DayOfWeek.TUESDAY); } if (record.get("wednesday").equals("1")) { daysOfWeek.add(DayOfWeek.WEDNESDAY); } if (record.get("thursday").equals("1")) { daysOfWeek.add(DayOfWeek.THURSDAY); } if (record.get("friday").equals("1")) { daysOfWeek.add(DayOfWeek.FRIDAY); } if (record.get("saturday").equals("1")) { daysOfWeek.add(DayOfWeek.SATURDAY); } if (record.get("sunday").equals("1")) { daysOfWeek.add(DayOfWeek.SUNDAY); } LocalDate targetDate = start; while (!targetDate.isAfter(end)) { if (daysOfWeek.contains(targetDate.getDayOfWeek())) { serviceTypesMap.put(targetDate, serviceType); } targetDate = targetDate.plusDays(1); } } }
From source file:Main.java
/** * The adjustInto method accepts a Temporal instance * and returns an adjusted LocalDate. If the passed in * parameter is not a LocalDate, then a DateTimeException is thrown. *///from w w w .j a v a2 s. c o m public Temporal adjustInto(Temporal input) { LocalDate date = LocalDate.from(input); int day; if (date.getDayOfMonth() < 15) { day = 15; } else { day = date.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); } date = date.withDayOfMonth(day); if (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY) { date = date.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY)); } return input.with(date); }
From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java
@Override @Transactional(readOnly = true)/* ww w . j a va 2 s . c om*/ 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:nu.yona.server.analysis.service.ActivityServiceTest.java
private LocalDate getWeekStartDate(LocalDate date) { switch (date.getDayOfWeek()) { case SUNDAY://from w w w . j a v a2 s .c o m return date; default: return date.minusDays(date.getDayOfWeek().getValue()); } }
From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java
@Override @Transactional(readOnly = false)//from w w w .java 2 s . co m public void reserver(final LocalDate startDate, final Famille famille, final List<DayOfWeek> jours) throws TechnicalException { 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()); try { this.reserver(date, ict.getIndividu().getId(), famille, jours.contains(date.getDayOfWeek())); } catch (TechnicalException e) { LOGGER.error("Une erreur technique s'est produite : " + e.getMessage(), e); } catch (FunctionalException e) { LOGGER.warn("Une erreur fonctionnelle s'est produite : " + e.getMessage(), e); } }); }); }
From source file:de.jfachwert.rechnung.Rechnungsmonat.java
/** * Diese Methode kann verwendet werden, um den ersten Montag im Monat * zu bestimmen. Dazu ruft man diese Methode einfach mit * {@link DayOfWeek#MONDAY} als Parameter auf. * //from w w w .ja v a 2 s . c o m * @param wochentag z.B. {@link DayOfWeek#MONDAY} * @return z.B. erster Arbeitstag * @since 0.6 */ public LocalDate ersterTag(DayOfWeek wochentag) { LocalDate tag = ersterTag(); while (tag.getDayOfWeek() != wochentag) { tag = tag.plusDays(1); } return tag; }
From source file:de.jfachwert.rechnung.Rechnungsmonat.java
/** * Diese Methode kann verwendet werden, um den letzten Freitag im Monat * zu bestimmen. Dazu ruft man diese Methode einfach mit * {@link DayOfWeek#FRIDAY} als Parameter auf. * * @param wochentag z.B. {@link DayOfWeek#FRIDAY} * @return z.B. letzter Arbeitstag/*from w w w . jav a 2 s.com*/ * @since 0.6 */ public LocalDate letzterTag(DayOfWeek wochentag) { LocalDate tag = ersterTag(); while (tag.getDayOfWeek() != wochentag) { tag = tag.minusDays(1); } return tag; }
From source file:de.jfachwert.rechnung.Rechnungsmonat.java
/** * Diese Methode liefert den ersten Arbeitstag eines Monats. Allerdings * werden dabei keine Feiertag beruecksichtigt, sondern nur die Wochenende, * die auf einen ersten des Monats fallen, werden berucksichtigt. * //www .j ava2 s .c om * @return erster Arbeitstag * @since 0.6 */ public LocalDate ersterArbeitstag() { LocalDate tag = ersterTag(); switch (tag.getDayOfWeek()) { case SATURDAY: return tag.plusDays(2); case SUNDAY: return tag.plusDays(1); default: return tag; } }
From source file:de.jfachwert.rechnung.Rechnungsmonat.java
/** * Diese Methode liefert den letzten Arbeitstag eines Monats. Allerdings * werden dabei keine Feiertag beruecksichtigt, sondern nur die Wochenende, * die auf einen letzten des Monats fallen, werden berucksichtigt. * * @return letzter Arbeitstag/*from ww w .j av a 2s.co m*/ * @since 0.6 */ public LocalDate letzterArbeitstag() { LocalDate tag = letzterTag(); switch (tag.getDayOfWeek()) { case SATURDAY: return tag.minusDays(1); case SUNDAY: return tag.minusDays(2); default: return tag; } }