Example usage for org.joda.time DateTime withDayOfWeek

List of usage examples for org.joda.time DateTime withDayOfWeek

Introduction

In this page you can find the example usage for org.joda.time DateTime withDayOfWeek.

Prototype

public DateTime withDayOfWeek(int dayOfWeek) 

Source Link

Document

Returns a copy of this datetime with the day of week field updated.

Usage

From source file:org.onebusaway.nextbus.impl.util.DateUtil.java

License:Apache License

public static List<Long> getWeekdayDateTimes(String timeZoneId) {

    List<Long> weekdayTimes = new ArrayList<Long>();

    DateTimeZone timeZone = DateTimeZone.forID(timeZoneId);
    DateTime today = new DateTime(timeZone).withTimeAtStartOfDay();

    weekdayTimes.add(today.withDayOfWeek(DateTimeConstants.MONDAY).getMillis() + 60000);
    weekdayTimes.add(today.withDayOfWeek(DateTimeConstants.TUESDAY).getMillis() + 60000);
    weekdayTimes.add(today.withDayOfWeek(DateTimeConstants.WEDNESDAY).getMillis() + 60000);
    weekdayTimes.add(today.withDayOfWeek(DateTimeConstants.THURSDAY).getMillis() + 60000);
    weekdayTimes.add(today.withDayOfWeek(DateTimeConstants.FRIDAY).getMillis() + 60000);

    return weekdayTimes;
}

From source file:org.onebusaway.nextbus.impl.util.DateUtil.java

License:Apache License

public static List<Long> getWeekendDateTimes(String timeZoneId) {

    List<Long> weekendTimes = new ArrayList<Long>();

    DateTimeZone timeZone = DateTimeZone.forID(timeZoneId);
    DateTime today = new DateTime(timeZone).withTimeAtStartOfDay();

    weekendTimes.add(today.withDayOfWeek(DateTimeConstants.SATURDAY).getMillis() + 60000);
    weekendTimes.add(today.withDayOfWeek(DateTimeConstants.SUNDAY).getMillis() + 60000);

    return weekendTimes;

}

From source file:org.opencastproject.util.DateTimeSupport.java

License:Educational Community License

/**
 * Forward to the next week day.// ww w  . java  2  s  . c o  m
 * <p/>
 * If it's Monday forwarding to Tuesday will add 1 day. If it's Friday forwarding to Thursday will go to next week's
 * Thursday which is adding 6 days. Forward to Monday if on Monday simply returns <code>time</code>.
 *
 * @param weekDay
 *          like described in {@link org.joda.time.DateTimeConstants}
 */
public static DateTime toNextWeekDay(DateTime time, int weekDay) {
    return time.getDayOfWeek() <= weekDay ? time.withDayOfWeek(weekDay)
            : time.plusWeeks(1).withDayOfWeek(weekDay);
}

From source file:pt.ist.fenixedu.integration.api.FenixAPIv1.java

License:Open Source License

private FenixSpace.Room getFenixRoom(Space room, java.util.Calendar rightNow) {

    InfoSiteRoomTimeTable bodyComponent = RoomSiteComponentBuilder.getInfoSiteRoomTimeTable(rightNow, room,
            null);// w w  w .  ja va2 s .  c o  m
    List<FenixRoomEvent> roomEvents = new ArrayList<FenixRoomEvent>();

    try {
        for (Object occupation : bodyComponent.getInfoShowOccupation()) {
            InfoShowOccupation showOccupation = (InfoShowOccupation) occupation;
            DateTime date = new DateTime(rightNow);
            DateTime newDate = date
                    .withDayOfWeek(showOccupation.getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat());
            String day = formatDay.print(newDate);

            FenixRoomEvent roomEvent = null;

            if (showOccupation instanceof InfoLesson || showOccupation instanceof InfoLessonInstance) {
                InfoShowOccupation lesson = showOccupation;
                InfoExecutionCourse infoExecutionCourse = lesson.getInfoShift().getInfoDisciplinaExecucao();

                String start = formatHour.print(lesson.getInicio().getTimeInMillis());
                String end = formatHour.print(lesson.getFim().getTimeInMillis());
                String weekday = lesson.getDiaSemana().getDiaSemanaString();

                FenixPeriod period = new FenixPeriod(day + " " + start, day + " " + end);

                String info = lesson.getInfoShift().getShiftTypesCodePrettyPrint();

                FenixCourse course = new FenixCourse(infoExecutionCourse.getExecutionCourse());

                roomEvent = new FenixRoomEvent.LessonEvent(start, end, weekday, day, period, info, course);

            } else if (showOccupation instanceof InfoWrittenEvaluation) {
                InfoWrittenEvaluation infoWrittenEvaluation = (InfoWrittenEvaluation) showOccupation;

                List<FenixCourse> courses = new ArrayList<>();

                for (int iterEC = 0; iterEC < infoWrittenEvaluation.getAssociatedExecutionCourse()
                        .size(); iterEC++) {
                    InfoExecutionCourse infoEC = infoWrittenEvaluation.getAssociatedExecutionCourse()
                            .get(iterEC);
                    courses.add(new FenixCourse(infoEC.getExecutionCourse()));
                }

                String start = null;
                String end = null;
                String weekday = null;

                if (infoWrittenEvaluation instanceof InfoExam) {
                    InfoExam infoExam = (InfoExam) infoWrittenEvaluation;
                    start = infoExam.getBeginningHour();
                    end = infoExam.getEndHour();
                    weekday = infoWrittenEvaluation.getDiaSemana().getDiaSemanaString();

                    FenixPeriod period = new FenixPeriod(day + " " + start, day + " " + end);

                    Integer season = infoExam.getSeason().getSeason();

                    roomEvent = new FenixRoomEvent.WrittenEvaluationEvent.ExamEvent(start, end, weekday, day,
                            period, courses, season);

                } else if (infoWrittenEvaluation instanceof InfoWrittenTest) {
                    InfoWrittenTest infoWrittenTest = (InfoWrittenTest) infoWrittenEvaluation;
                    String description = infoWrittenTest.getDescription();
                    start = formatHour.print(infoWrittenTest.getInicio().getTimeInMillis());
                    end = formatHour.print(infoWrittenTest.getFim().getTimeInMillis());
                    weekday = infoWrittenTest.getDiaSemana().getDiaSemanaString();

                    FenixPeriod period = new FenixPeriod(day + " " + start, day + " " + end);

                    roomEvent = new FenixRoomEvent.WrittenEvaluationEvent.TestEvent(start, end, weekday, day,
                            period, courses, description);
                }

            } else if (showOccupation instanceof InfoOccupation) {

                InfoOccupation infoGenericEvent = (InfoOccupation) showOccupation;
                String description = infoGenericEvent.getDescription();
                String title = infoGenericEvent.getTitle();
                String start = formatHour.print(infoGenericEvent.getInicio().getTimeInMillis());
                String end = formatHour.print(infoGenericEvent.getFim().getTimeInMillis());
                ;
                String weekday = infoGenericEvent.getDiaSemana().getDiaSemanaString();
                FenixPeriod period = new FenixPeriod(day + " " + start, day + " " + end);

                roomEvent = new FenixRoomEvent.GenericEvent(start, end, weekday, day, period, description,
                        title);
            }

            if (roomEvent != null) {
                roomEvents.add(roomEvent);
            }

        }

        return new FenixSpace.Room(room, roomEvents);

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw newApplicationError(Status.INTERNAL_SERVER_ERROR, "berserk!", "something went wrong");
    }
}