Example usage for org.joda.time DateMidnight withField

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

Introduction

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

Prototype

public DateMidnight withField(DateTimeFieldType fieldType, int value) 

Source Link

Document

Returns a copy of this date with the specified field set to a new value.

Usage

From source file:net.sourceforge.fenixedu.domain.Attends.java

License:Open Source License

public Interval getCurrentWeek() {
    final DateMidnight beginningOfSemester = new DateMidnight(getBegginingOfLessonPeriod());
    final DateMidnight firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
    final int currentWeek = calculateCurrentWeekOffset();
    final DateMidnight start = firstMonday.plusWeeks(currentWeek);
    return new Interval(start, start.plusWeeks(1));
}

From source file:net.sourceforge.fenixedu.domain.Attends.java

License:Open Source License

public Interval getResponseWeek() {
    final DateMidnight beginningOfSemester = new DateMidnight(getBegginingOfLessonPeriod());
    final DateMidnight firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
    final DateMidnight secondMonday = firstMonday.plusWeeks(1);

    final DateMidnight endOfSemester = new DateMidnight(getEndOfExamsPeriod());
    final DateMidnight lastMonday = endOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
    final DateMidnight endOfResponsePeriod = lastMonday.plusWeeks(2);

    return (secondMonday.isEqualNow() || secondMonday.isBeforeNow()) && endOfResponsePeriod.isAfterNow()
            ? getPreviousWeek()//  www  . jav a  2 s  . c om
            : null;
}

From source file:net.sourceforge.fenixedu.domain.Attends.java

License:Open Source License

public int calculateCurrentWeekOffset() {
    final DateMidnight beginningOfLessonPeriod = new DateMidnight(getBegginingOfLessonPeriod());
    final DateMidnight firstMonday = beginningOfLessonPeriod.withField(DateTimeFieldType.dayOfWeek(), 1);
    final DateMidnight thisMonday = new DateMidnight().withField(DateTimeFieldType.dayOfWeek(), 1);

    final Interval interval = new Interval(firstMonday, thisMonday);

    return interval.toPeriod(PeriodType.weeks()).getWeeks();
}

From source file:net.sourceforge.fenixedu.domain.ExecutionSemester.java

License:Open Source License

public DateMidnight getThisMonday() {
    final DateTime beginningOfSemester = getBeginDateYearMonthDay().toDateTimeAtMidnight();
    final DateTime endOfSemester = getEndDateYearMonthDay().toDateTimeAtMidnight();

    if (beginningOfSemester.isAfterNow() || endOfSemester.isBeforeNow()) {
        return null;
    }/*from  w  w  w.j av  a2 s .c o  m*/

    final DateMidnight now = new DateMidnight();
    return now.withField(DateTimeFieldType.dayOfWeek(), 1);
}