Example usage for org.joda.time DateMidnight getDayOfWeek

List of usage examples for org.joda.time DateMidnight getDayOfWeek

Introduction

In this page you can find the example usage for org.joda.time DateMidnight getDayOfWeek.

Prototype

public int getDayOfWeek() 

Source Link

Document

Get the day of week field value.

Usage

From source file:com.google.android.apps.paco.TimeUtil.java

License:Open Source License

public static DateMidnight getMondayOfWeek(DateTime now) {
    DateMidnight mondayOfWeek = now.toDateMidnight();
    int dow = mondayOfWeek.getDayOfWeek();
    if (dow != DateTimeConstants.MONDAY) {
        mondayOfWeek = mondayOfWeek.minusDays(dow - 1);
    }//from   ww  w .j a v a2s. c o m
    return mondayOfWeek;
}

From source file:com.google.sampling.experiential.server.MapServiceImpl.java

License:Open Source License

/**
 * @param dateMidnight//from   w  ww .  jav  a  2 s . com
 * @return
 */
private DateMidnight getBeginningOfWeek(DateMidnight dateMidnight) {
    int dow = dateMidnight.getDayOfWeek();
    int daysToBeginning = dow - DateTimeConstants.MONDAY;
    if (daysToBeginning != 0) {
        return dateMidnight.minusDays(daysToBeginning);
    }
    return dateMidnight;
}

From source file:dk.teachus.backend.domain.impl.PeriodImpl.java

License:Apache License

public boolean hasWeekDay(DateMidnight weekDayDate) {
    DateMidnight dateMidnight = weekDayDate;
    dateMidnight.getDayOfWeek();

    boolean hasWeekDay = false;
    for (WeekDay weekDay : weekDays) {
        if (weekDay.getYodaWeekDay() == dateMidnight.getDayOfWeek()) {
            hasWeekDay = true;/*from   w ww  .j  a  va  2 s .com*/
            break;
        }
    }

    return hasWeekDay;
}

From source file:org.jasig.portlet.courses.mvc.wrapper.CourseSectionWrapper.java

License:Apache License

/**
 * For individual meeting days/*from  w ww  .j  a  va 2  s.  c  om*/
 * <p>
 * Used by the Final Exam Grid
 *
 * @param course  Reference Course.  {@link #setCourse(Course)}
 * @param section Reference section, which is a member of course
 *                {@link #setCourseSection(CourseSection)}
 * @param meeting Reference meeting, which is a member of section
 *                {@link #setCourseMeeting(CourseMeeting)}
 *
 *                Used to set the Start date reference,
 *                Is used to set day of week and name.<br/>
 *                {@link #setDay(DayEnum)}<br/>
 *                {@link DayEnum}
 * @param url     The URL for the detail view of course and section
 */
public CourseSectionWrapper(Course course, CourseSection section, CourseMeeting meeting, String url) {
    DateMidnight date = meeting.getStartDate();
    this.setStartDateObj(date);
    this.setDay(dayArr[date.getDayOfWeek()]);
    this.setUrl(url);
    this.setCourse(course);
    this.setCourseSection(section);
    this.setCourseMeeting(meeting);
    this.setSessionCode(getCourseSectionAdditionalInfoValue(section, "sessionCode"));
    this.setSessionStartEndDate(getCourseSectionAdditionalInfoValue(section, "sessionStartEndDate"));
}

From source file:org.jasig.portlet.courses.mvc.wrapper.CourseSectionWrapper.java

License:Apache License

@JsonIgnore
public int getExamStartSunday() {
    if (this.getStartDateObj() == null) {
        return 0;
    }//from  www .  j a v  a2 s . c  o m

    DateMidnight date = this.getStartDateObj();

    if (date.getDayOfWeek() == DateTimeConstants.SUNDAY) {
        return date.getDayOfMonth();
    }

    return date.withDayOfWeek(DateTimeConstants.SUNDAY).minusWeeks(1).getDayOfMonth();
}

From source file:org.kuali.student.enrollment.class2.acal.service.impl.AcademicCalendarViewHelperServiceImpl.java

License:Educational Community License

/**
 * Calculate and returns the valid number of final exam period days based on the excludeSaturday/excludeSunday setting.
 * Also, overlapping non-instructional holidays will be subtracted as well.
 *
 * @param examPeriodWrapper exam period wrapper
 * @param holidayInfos list of holidayinfos of the academic calendar
 *///w ww  .j ava2s . c o m
protected int getDaysForExamPeriod(ExamPeriodWrapper examPeriodWrapper, List<HolidayInfo> holidayInfos,
        ContextInfo contextInfo) throws Exception {
    //trap null parameters
    if (examPeriodWrapper == null) {
        throw new Exception("Exam Period wrapper is null");
    }

    int examPeriodDays = 0;
    boolean excludeSaturday = examPeriodWrapper.isExcludeSaturday();
    boolean excludeSunday = examPeriodWrapper.isExcludeSunday();

    DateMidnight currentDateExamPeriod = new DateMidnight(examPeriodWrapper.getStartDate().getTime());
    DateMidnight endDateExamPeriod = new DateMidnight(examPeriodWrapper.getEndDate().getTime());

    // go from start to end and count exam period days
    while (currentDateExamPeriod.compareTo(endDateExamPeriod) <= 0) {
        // if it is Saturday or Sunday and the exam period set exclude Saturday or Sunday attr
        // do not count that day
        if (!(((currentDateExamPeriod.getDayOfWeek() == DateTimeConstants.SATURDAY) && excludeSaturday)
                || ((currentDateExamPeriod.getDayOfWeek() == DateTimeConstants.SUNDAY) && excludeSunday))) {
            ++examPeriodDays;
        }

        currentDateExamPeriod = currentDateExamPeriod.plusDays(1);
    }

    //if there is a holiday calendar for the academic calendar where the exam period is in,
    //check if there are holidays overlapping with the exam period
    if (holidayInfos != null && !holidayInfos.isEmpty()) {
        List<DateMidnight> holidayDatesToSubtract = new ArrayList<DateMidnight>();
        for (HolidayInfo holidayInfo : holidayInfos) {
            Boolean isInstDay = holidayInfo.getIsInstructionalDay();
            Boolean isDateRange = holidayInfo.getIsDateRange();
            Date holStartDate = holidayInfo.getStartDate();
            Date holEndDate = holidayInfo.getEndDate();

            // If's it's not a range then the start and end dates are the same
            if (!isDateRange) {
                holEndDate = holStartDate;
            }

            // if holiday is an instructional day, it doesn't need to be subtracted from the exam period
            if (!isInstDay) {
                DateMidnight currentDate = new DateMidnight(holStartDate.getTime());
                DateMidnight stopDate = new DateMidnight(holEndDate.getTime());
                while (currentDate.compareTo(stopDate) <= 0) {
                    if (doDatesOverlap(examPeriodWrapper.getStartDate(), examPeriodWrapper.getEndDate(),
                            currentDate.toDate(), currentDate.toDate())) {
                        //if holiday is on Saturday or Sunday and excludeSaturday/excludeSunday is set,
                        //the holiday doesn't need to be subtracted again because the Saturday/Sunday has already been excluded
                        if (!(((currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) && excludeSaturday)
                                || ((currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY)
                                        && excludeSunday))) {
                            if (!holidayDatesToSubtract.contains(currentDate)) {
                                holidayDatesToSubtract.add(currentDate);
                                --examPeriodDays;
                            }
                        }
                    }
                    currentDate = currentDate.plusDays(1);
                }
            }
        }
    }

    return examPeriodDays;
}