Example usage for java.time DayOfWeek SUNDAY

List of usage examples for java.time DayOfWeek SUNDAY

Introduction

In this page you can find the example usage for java.time DayOfWeek SUNDAY.

Prototype

DayOfWeek SUNDAY

To view the source code for java.time DayOfWeek SUNDAY.

Click Source Link

Document

The singleton instance for the day-of-week of Sunday.

Usage

From source file:Main.java

public static void main(String[] args) {
    DayOfWeek dayOfWeek = DayOfWeek.SUNDAY;
    System.out.println(dayOfWeek.name());
    System.out.println(dayOfWeek.getValue());
    System.out.println(dayOfWeek.ordinal());
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate ld1 = LocalDate.of(2014, Month.MAY, 21);
    System.out.println(ld1);// w  ww.j  a v  a 2 s.c o m
    LocalDate ld2 = ld1.with(TemporalAdjusters.dayOfWeekInMonth(5, DayOfWeek.SUNDAY));
    System.out.println(ld2);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, Month.FEBRUARY, 25); // 2014-02-25

    // next Sunday (2014-03-02)
    LocalDate nextSunday = date.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));

    System.out.println(nextSunday);
}

From source file:Main.java

public static LocalDate[] getWeekday(LocalDate date) {
    int DAYS_OF_WEEK = 7;

    if (date == null) {
        date = LocalDate.now();// w  w  w.  j  a v  a2s  .co m
    }

    LocalDate begin = null;
    if (date.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
        begin = date;
    } else {
        begin = date.minusDays(date.getDayOfWeek().getValue());
    }
    LocalDate end = begin.plusDays(DAYS_OF_WEEK - 1);

    LocalDate localDate[] = { begin, end };

    return localDate;

}

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.
 */// w  w  w .  j  a  v a  2  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: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;/*  www .ja v a2  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:org.thevortex.lighting.jinks.robot.Recurrence.java

/**
 * @return the ICAL-formatted string/*from  w w w. jav a  2 s  . c  o m*/
 */
@Override
public String toString() {
    StringBuilder formatted = new StringBuilder(DTSTART)
            .append(ZonedDateTime.now().with(startTime).truncatedTo(ChronoUnit.MINUTES).format(ICAL_DT));

    // if we have a duration, there's an end
    if (duration != null) {
        formatted.append('\n').append(DTEND).append(ZonedDateTime.now().with(startTime.plus(duration))
                .truncatedTo(ChronoUnit.MINUTES).format(ICAL_DT));
    }

    // always a frequency
    formatted.append('\n').append(RRULE).append(FREQ).append(frequency);

    if (frequency == Frequency.WEEKLY) {
        // build the buffer of days
        StringBuilder dayBuilder = new StringBuilder();
        boolean notFirst = false;
        DayOfWeek lastDay = null;
        for (DayOfWeek day : days) {
            if (notFirst) {
                dayBuilder.append(',');
            }
            notFirst = true;
            dayBuilder.append(day.name().substring(0, 2));
            lastDay = day;
        }
        String formattedDays = dayBuilder.toString();

        // if SUNDAY is at the end, move it to the front
        if (lastDay == DayOfWeek.SUNDAY) {
            formattedDays = "SU," + formattedDays.substring(0, formattedDays.lastIndexOf(","));
        }
        // spit it out
        formatted.append(';').append(BYDAY).append(formattedDays);
    }
    return formatted.toString();
}

From source file:mesclasses.view.JourneeController.java

/**
 * Initializes the controller class.//from   w  w w  . j a v  a 2  s. c  o  m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    LogUtil.logStart();
    name = "Journee Ctrl";
    super.initialize(url, rb);
    LOG.debug("Initialisation de " + name);
    initTabs();
    Btns.makeLeft(previousDayBtn);
    Btns.makeRight(nextDayBtn);
    Btns.makeLeft(seanceSelect.getBtnLeft());
    Btns.makeRight(seanceSelect.getBtnRight());

    Btns.makeAdd(addCoursBtn);
    Btns.makeDelete(remCoursBtn);

    Btns.tooltip(previousDayBtn, "Jour prcdent");
    Btns.tooltip(nextDayBtn, "Jour suivant");
    Btns.tooltip(seanceSelect.getBtnLeft(), "Sance prcdente");
    Btns.tooltip(seanceSelect.getBtnRight(), "Sance suivante");
    Btns.tooltip(addCoursBtn, "Ajouter une sance ponctuelle");
    Btns.tooltip(remCoursBtn, "Supprimer la sance ponctuelle");
    Btns.tooltip(switchNonActifsBtn, "active/dsactive l'affichage des lves inactifs");
    Btns.tooltip(rapportsBtn, "Ouvre la page des rapports trimestriels pour la classe");
    Btns.tooltip(punitionsBtn, "Ouvre le suivi des punitions, devoirs et mots pour la classe");
    Btns.tooltip(postItBtn, "ouvre le postIt de la classe");
    Btns.tooltip(ramasserBtn, "ouvre la fentre des actions  faire pour la classe");

    currentDate.setDayCellFactory(new TunedDayCellFactory().setAllowSundays(false));
    currentDate.setConverter(NodeUtil.DATE_WITH_DAY_NAME);

    currentDate.valueProperty().addListener(dateListener);

    displayNonActifs = new SimpleBooleanProperty(false);
    switchNonActifsBtn.setText("Afficher inactifs");
    displayNonActifs.addListener((observable, oldValue, newValue) -> {

        LOG.debug("Switch actifs/inactifs");
        switchNonActifsBtn.setText(displayNonActifs.get() ? "Masquer inactifs" : "Afficher inactifs");
        refreshGrid();
    });

    seanceSelect.addChangeListener((ob, o, n) -> {
        LOG.debug("seanceSelect changed --> reloading");
        loadCurrentSeance();
    });
    // activation du bouton remCours si besoin
    rapportsBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty()));
    punitionsBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty()));
    postItBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty()));

    // on ne change que la date, le listener sur currentDate se charge du reste
    LocalDate today = LocalDate.now();
    if (today.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
        today = today.minusDays(1);
    }
    LOG.debug("Initializing with today's date");
    currentDate.setValue(today);
    LogUtil.logEnd();
}

From source file:memoryaid.SetReminderController.java

@FXML
private void handleSetReminderBtnAction(ActionEvent event) throws Exception {

    System.out.println("You clicked Add Reminder!");

    String rType = (String) reminderTypeBox.getValue();
    String rName = reminderNameText.getText();
    LocalDate rSDate = startDateId.getValue();
    LocalDate rEDate = endDateId.getValue();
    List<LocalDate> reminderDates = new ArrayList<>();

    String hours = (String) reminderHhBox.getValue();
    String minutes = (String) reminderMmBox.getValue();
    String seconds = (String) reminderSsBox.getValue();
    ObservableList<String> repeat = multiSelectComboBox.getCheckModel().getCheckedItems();

    String imgPath = imagePathText.getText();

    if (rType == null || rName == null || rSDate == null || rEDate == null || hours == null || minutes == null
            || seconds == null || repeat.size() == 0 || imgPath == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error Dialog");
        alert.setHeaderText("Oops, an Error Dialog");
        alert.setContentText("Please fill all the fields");
        alert.showAndWait();//  www  . j  a  v  a2  s. c o  m
        System.out.println("Please fill all the fields");
    } else if (rSDate.isAfter(rEDate) == true) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error Dialog");
        alert.setHeaderText("Oops, an Error Dialog");
        alert.setContentText("End date cannot be before the Start date");
        alert.showAndWait();
        System.out.println("End date should be greater than start date");
    } else {
        String rTime = hours + ":" + minutes + ":" + seconds;
        if (rType != null && rName != null && !rName.isEmpty() && rEDate != null && hours != null
                && minutes != null && seconds != null && repeat != null && imgPath != null) {

            String destinationPath = "/Users/madhaviunnam/NetBeansProjects/MemoryAid/src/Reminders";
            File destinationPathObject = new File(destinationPath + "/" + rName + ".png");
            File sourceFilePathObject = new File(imgPath);
            FileUtils.copyFile(sourceFilePathObject, destinationPathObject);

            System.out.println(
                    "You clicked Add Reminder!" + rType + rName + rSDate + rEDate + rTime + repeat + imgPath);
            System.out.println("****Inside if");
            Reminder reminderToSet = new Reminder();
            reminderToSet.setReminderName(rName);
            reminderToSet.setReminderType(rType);
            reminderToSet.setStartDate(rSDate);
            reminderToSet.setEndDate(rEDate);

            //endDateToCheck = rEDate.plusDays(1);

            if (repeat.contains("Every Monday")) {
                reminderToSet.setRepeatMon("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.MONDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatMon("false");
            }
            if (repeat.contains("Every Tuesday")) {
                reminderToSet.setRepeatTue("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.TUESDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatTue("false");
            }
            if (repeat.contains("Every Wednesday")) {
                reminderToSet.setRepeatWed("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.WEDNESDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatWed("false");
            }
            if (repeat.contains("Every Thursday")) {
                reminderToSet.setRepeatThu("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.THURSDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatThu("false");
            }
            if (repeat.contains("Every Friday")) {
                reminderToSet.setRepeatFri("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.FRIDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatFri("false");
            }
            if (repeat.contains("Every Saturday")) {
                reminderToSet.setRepeatSat("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.SATURDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatSat("false");
            }
            if (repeat.contains("Every Sunday")) {
                reminderToSet.setRepeatSun("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.SUNDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
            } else {
                reminderToSet.setRepeatSun("false");
            }
            if (repeat.contains("None")) {
                reminderToSet.setRepeatNone("true");
                reminderDates.add(rSDate);
            } else {
                reminderToSet.setRepeatNone("false");
            }

            System.out.println("%%%%Reminder DATes" + reminderDates);
            reminderToSet.setReminderTime(rTime);
            reminderToSet.setReminderStatus("New");

            DbConnection db = new DbConnection();
            Connection conn = db.connect();
            PreparedStatement preparedStmt = null;
            String insertSql = "INSERT into Reminders(ReminderType, ReminderName, StartDate, EndDate, ReminderTime, RepeatM, RepeatT, RepeatW, RepeatTH, RepeatF, RepeatSat, RepeatSun)"
                    + "values(?,?,?,?,?,?,?,?,?,?,?,?)";
            preparedStmt = conn.prepareStatement(insertSql);
            preparedStmt.setString(1, reminderToSet.getReminderType());
            preparedStmt.setString(2, reminderToSet.getReminderName());
            preparedStmt.setString(3, reminderToSet.getStartDate().toString());
            preparedStmt.setString(4, reminderToSet.getEndDate().toString());
            preparedStmt.setString(5, reminderToSet.getReminderTime());
            preparedStmt.setString(6, reminderToSet.getRepeatMon());
            preparedStmt.setString(7, reminderToSet.getRepeatTue());
            preparedStmt.setString(8, reminderToSet.getRepeatWed());
            preparedStmt.setString(9, reminderToSet.getRepeatThu());
            preparedStmt.setString(10, reminderToSet.getRepeatFri());
            preparedStmt.setString(11, reminderToSet.getRepeatSat());
            preparedStmt.setString(12, reminderToSet.getRepeatSun());

            preparedStmt.executeUpdate();
            System.out.println("Reminder Inserted Successfully  ");
            //Get the inserted reminders RId
            String getRIdsql = "Select max(RId) as RId from Reminders";
            ResultSet rSet = conn.createStatement().executeQuery(getRIdsql);
            int newRId = 0;
            while (rSet.next()) {
                newRId = rSet.getInt(1);

            }
            System.out.println("RID ^^^^^^^^" + newRId);
            PreparedStatement preparedStmtRDetails = null;
            for (int i = 0; i < reminderDates.size(); i++) {
                String rDetailsSql = "Insert into ReminderDetails(RId,DetailNum,ReminderDate,ReminderStatus)"
                        + " values(?,?,?,?)";
                preparedStmtRDetails = conn.prepareStatement(rDetailsSql);
                preparedStmtRDetails.setInt(1, newRId);
                preparedStmtRDetails.setInt(2, i);
                preparedStmtRDetails.setString(3, reminderDates.get(i).toString());
                preparedStmtRDetails.setString(4, "New");
                preparedStmtRDetails.executeUpdate();
                System.out.println("ReminderDetails Table Insert Successfull  ");
            }
            Parent setReminder = FXMLLoader.load(getClass().getResource("SetReminder.fxml"));
            Scene set_reminder_refresh_scene = new Scene(setReminder);
            Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
            app_stage.hide();
            app_stage.setScene(set_reminder_refresh_scene);
            app_stage.show();

        } else {
            System.out.println("Inside else");
            //show alert
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Error Dialog");
            alert.setHeaderText("Oops, an Error Dialog");
            alert.setContentText("Please fill all the fields");
            alert.showAndWait();

        }
    }

}