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.fenixedu.spaces.ui.SpaceSearchController.java

License:Open Source License

@RequestMapping(value = "/schedule/{space}/events", produces = "application/json; charset=utf-8")
public @ResponseBody String schedule(@PathVariable Space space, @RequestParam(required = false) String start,
        @RequestParam(required = false) String end, Model model) {
    DateTime beginDate;//w  ww. j a  v a 2 s . co m
    DateTime endDate;

    if (Strings.isNullOrEmpty(start)) {
        DateTime now = new DateTime();
        beginDate = now.withDayOfWeek(DateTimeConstants.MONDAY).withHourOfDay(0).withMinuteOfHour(0);
        endDate = now.withDayOfWeek(DateTimeConstants.SUNDAY).plusDays(1).withHourOfDay(0).withMinuteOfHour(0);
    } else {
        beginDate = new DateTime(Long.parseLong(start) * 1000);
        endDate = new DateTime(Long.parseLong(end) * 1000);
    }

    return occupationService.getOccupations(space, new Interval(beginDate, endDate));
}

From source file:org.fenixedu.ulisboa.specifications.ui.student.enrolment.ShiftEnrolmentByAcademicOfficeController.java

License:Open Source License

@RequestMapping(value = "currentSchedule.json/{registrationOid}/{executionSemesterOid}", produces = "application/json; charset=utf-8")
public @ResponseBody String schedule(@PathVariable("registrationOid") Registration registration,
        @PathVariable("executionSemesterOid") ExecutionSemester executionSemester) {

    checkUser();//  w ww . jav a2 s  .  c om

    final JsonArray result = new JsonArray();

    for (final Shift shift : registration.getShiftsFor(executionSemester)) {
        for (Lesson lesson : shift.getAssociatedLessonsSet()) {
            final DateTime now = new DateTime();
            final DateTime weekDay = now
                    .withDayOfWeek(lesson.getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat());
            final DateTime startTime = weekDay.withTime(lesson.getBeginHourMinuteSecond().getHour(),
                    lesson.getBeginHourMinuteSecond().getMinuteOfHour(), 0, 0);
            final DateTime endTime = weekDay.withTime(lesson.getEndHourMinuteSecond().getHour(),
                    lesson.getEndHourMinuteSecond().getMinuteOfHour(), 0, 0);

            final JsonObject event = new JsonObject();
            event.addProperty("id", lesson.getExternalId());
            event.addProperty("start", startTime.toString());
            event.addProperty("end", endTime.toString());
            event.addProperty("title", shift.getExecutionCourse().getName() + " ("
                    + shift.getShiftTypesCodePrettyPrint() + " - " + shift.getNome() + ")");
            event.addProperty("shiftId", shift.getExternalId());
            result.add(event);
        }
    }

    return result.toString();
}

From source file:org.fenixedu.ulisboa.specifications.ui.student.enrolment.ShiftEnrolmentController.java

License:Open Source License

@RequestMapping(value = "currentSchedule.json/{registrationOid}/{executionSemesterOid}", produces = "application/json; charset=utf-8")
public @ResponseBody String schedule(@PathVariable("registrationOid") Registration registration,
        @PathVariable("executionSemesterOid") ExecutionSemester executionSemester) {

    checkUser(registration);/*w  w  w  .  j ava2  s . c om*/

    final JsonArray result = new JsonArray();

    for (final Shift shift : registration.getShiftsFor(executionSemester)) {
        for (Lesson lesson : shift.getAssociatedLessonsSet()) {
            final DateTime now = new DateTime();
            final DateTime weekDay = now
                    .withDayOfWeek(lesson.getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat());
            final DateTime startTime = weekDay.withTime(lesson.getBeginHourMinuteSecond().getHour(),
                    lesson.getBeginHourMinuteSecond().getMinuteOfHour(), 0, 0);
            final DateTime endTime = weekDay.withTime(lesson.getEndHourMinuteSecond().getHour(),
                    lesson.getEndHourMinuteSecond().getMinuteOfHour(), 0, 0);

            final JsonObject event = new JsonObject();
            event.addProperty("id", lesson.getExternalId());
            event.addProperty("start", startTime.toString());
            event.addProperty("end", endTime.toString());
            event.addProperty("title", shift.getExecutionCourse().getName() + " ("
                    + shift.getShiftTypesCodePrettyPrint() + " - " + shift.getNome() + ")");
            result.add(event);
        }
    }

    return result.toString();
}

From source file:org.kairosdb.core.aggregator.RangeAggregator.java

License:Apache License

/**
 For YEARS, MONTHS, WEEKS, DAYS://  w  w w  .  j a  va 2s  .c  o  m
 Computes the timestamp of the first millisecond of the day
 of the timestamp.
 For HOURS,
 Computes the timestamp of the first millisecond of the hour
 of the timestamp.
 For MINUTES,
 Computes the timestamp of the first millisecond of the minute
 of the timestamp.
 For SECONDS,
 Computes the timestamp of the first millisecond of the second
 of the timestamp.
 For MILLISECONDS,
 returns the timestamp
        
 @param timestamp
 @return
 */
private long alignRangeBoundary(long timestamp) {
    DateTime dt = new DateTime(timestamp, m_timeZone);
    TimeUnit tu = m_sampling.getUnit();
    switch (tu) {
    case YEARS:
        dt = dt.withDayOfYear(1).withMillisOfDay(0);
        break;
    case MONTHS:
        dt = dt.withDayOfMonth(1).withMillisOfDay(0);
        break;
    case WEEKS:
        dt = dt.withDayOfWeek(1).withMillisOfDay(0);
        break;
    case DAYS:
    case HOURS:
    case MINUTES:
    case SECONDS:
        dt = dt.withHourOfDay(0);
        dt = dt.withMinuteOfHour(0);
        dt = dt.withSecondOfMinute(0);
    default:
        dt = dt.withMillisOfSecond(0);
        break;
    }
    return dt.getMillis();
}

From source file:org.kemri.wellcome.dhisreport.api.utils.WeeklyPeriod.java

License:Open Source License

public WeeklyPeriod(Date date) {
    DateTime dt = new DateTime(date);
    startDate = dt.withDayOfWeek(DateTimeConstants.MONDAY).toDate();
    endDate = dt.withDayOfWeek(DateTimeConstants.SUNDAY).withTime(23, 59, 59, 999).toDate();
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

@Override
public DateTime getNextAccrualIntervalDate(String earnInterval, DateTime aDate) {
    DateTime nextAccrualIntervalDate = null;

    if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) {
        nextAccrualIntervalDate = aDate;
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) {
        if (aDate.getDayOfWeek() != DateTimeConstants.SATURDAY) {
            nextAccrualIntervalDate = aDate.withDayOfWeek(DateTimeConstants.SATURDAY);
        } else {/*  w w  w  . j  a  v a2 s. c o m*/
            nextAccrualIntervalDate = aDate.withWeekOfWeekyear(1);
        }
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) {
        if (aDate.getDayOfMonth() <= 15) {
            nextAccrualIntervalDate = aDate.withDayOfMonth(15);
        } else {
            nextAccrualIntervalDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue());
        }
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) {
        nextAccrualIntervalDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue());
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) {
        nextAccrualIntervalDate = aDate.withDayOfYear(aDate.dayOfYear().getMaximumValue());
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) {
        nextAccrualIntervalDate = aDate;
    }

    return nextAccrualIntervalDate;
}

From source file:org.mifos.calendar.CalendarUtils.java

License:Open Source License

public static DateTime nearestDayOfWeekTo(final int dayOfWeek, final DateTime date) {

    DateTime withDayOfWeek = date.withDayOfWeek(dayOfWeek);

    if (date.getYear() == withDayOfWeek.getYear()) {

        if (date.getDayOfYear() > withDayOfWeek.getDayOfYear()) {
            return withDayOfWeek.plusWeeks(1);
        }//from   w ww  .  j a  v a 2  s.  c  om

        return withDayOfWeek;
    }

    // back a year
    if (date.getYear() > withDayOfWeek.getYear()) {
        return withDayOfWeek.plusWeeks(1);
    }

    return withDayOfWeek;
}

From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithROD.java

License:Open Source License

protected void getMeetingStartDate() {
    sanitizeDays();/*from  w  ww  . j  a  v  a  2s  .  c om*/
    DateTime initialDate = this.createdDate;
    initialDate = initialDate.withDayOfMonth(1);
    initialDate = initialDate.plusWeeks((this.rankOfDays - 1));
    initialDate = initialDate.withDayOfWeek(this.days);
    if (initialDate.isBefore(this.createdDate) || initialDate.isEqual(this.createdDate)) {
        initialDate = initialDate.plusMonths(1);
        initialDate = initialDate.withDayOfMonth(1);
        initialDate = initialDate.plusWeeks((this.rankOfDays - 1));
        initialDate = initialDate.withDayOfWeek(this.days);
    }
    this.startDate = initialDate;
}

From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithROD.java

License:Open Source License

public void generateSchedule(int numberOfDates) {
    numberOfDates--;/*from   w  w w .  ja v a 2 s .  c om*/
    getMeetingStartDate();
    fastForwardTillDisbursement();
    DateTime meetingScheduleDate = this.startDate;
    Date meetingDateInMifosFormat;
    for (int i = 0; i <= numberOfDates; i++) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        meetingDateInMifosFormat = getWorkingDay(meetingScheduleDate).toDate();
        this.scheduleList.add(formatter.format(meetingDateInMifosFormat));
        meetingScheduleDate = meetingScheduleDate.plusMonths(this.recAfter);
        meetingScheduleDate = meetingScheduleDate.withDayOfMonth(1);
        meetingScheduleDate = meetingScheduleDate.plusWeeks((this.rankOfDays - 1));
        meetingScheduleDate = meetingScheduleDate.withDayOfWeek(this.days);
    }
}

From source file:org.obm.imap.archive.services.SchedulingDatesService.java

License:Open Source License

private DateTime weeklyNextTreatmentDate(SchedulingConfiguration schedulingConfiguration,
        DateTime currentDateTime, DateTime currentDateWithScheduledTime) {
    DateTime dayOfWeek = currentDateWithScheduledTime
            .withDayOfWeek(schedulingConfiguration.getDayOfWeek().getSpecificationValue());
    if (dayOfWeek.isAfter(currentDateTime)) {
        return dayOfWeek;
    }//from w w  w  . jav a 2s.  c  om
    return dayOfWeek.plusWeeks(1);
}