List of usage examples for org.joda.time DateTime withDayOfWeek
public DateTime withDayOfWeek(int dayOfWeek)
From source file:net.sourceforge.fenixedu.util.renderer.GanttDiagram.java
License:Open Source License
private void calculateFirstAndLastInstantInWeeklyMode(YearMonthDay begin) { if (begin == null) { throw new IllegalArgumentException(); }//from w ww. j a v a 2 s . com DateTime beginDateTime = begin.toDateTimeAtMidnight(); beginDateTime = (beginDateTime.getDayOfWeek() != 1) ? beginDateTime.withDayOfWeek(1) : beginDateTime; setFirstInstant(beginDateTime); setLastInstant(beginDateTime.plusDays(6)); }
From source file:net.sourceforge.fenixedu.webServices.jersey.api.FenixAPIv1.java
License:Open Source License
private FenixSpace.Room getFenixRoom(Space room, java.util.Calendar rightNow) { InfoSiteRoomTimeTable bodyComponent = new InfoSiteRoomTimeTable(); RoomSiteComponentBuilder builder = new RoomSiteComponentBuilder(); List<FenixRoomEvent> roomEvents = new ArrayList<FenixRoomEvent>(); try {/* www. j a v a 2s.c o m*/ builder.getComponent(bodyComponent, rightNow, room, null); for (Object occupation : bodyComponent.getInfoShowOccupation()) { InfoShowOccupation showOccupation = (InfoShowOccupation) occupation; DateTime date = new DateTime(rightNow); DateTime newDate = date .withDayOfWeek(showOccupation.getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat()); String day = newDate.toString("dd/MM/yyyy"); FenixRoomEvent roomEvent = null; if (showOccupation instanceof InfoLesson || showOccupation instanceof InfoLessonInstance) { InfoShowOccupation lesson = showOccupation; InfoExecutionCourse infoExecutionCourse = lesson.getInfoShift().getInfoDisciplinaExecucao(); String start = dataFormatHour.format(lesson.getInicio().getTime()); String end = dataFormatHour.format(lesson.getFim().getTime()); 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 = dataFormatHour.format(infoWrittenTest.getInicio().getTime()); end = dataFormatHour.format(infoWrittenTest.getFim().getTime()); 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 = dataFormatHour.format(infoGenericEvent.getInicio().getTime()); String end = dataFormatHour.format(infoGenericEvent.getFim().getTime()); 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"); } }
From source file:org.efaps.esjp.common.datetime.JodaTimeUtils.java
License:Apache License
/** * @param _parameter parameter as passed by the eFaps API * @return new DateTime/*from w w w.ja v a 2 s. co m*/ * @throws EFapsException on error */ public static DateTime getDefaultvalue(final Parameter _parameter) throws EFapsException { final JodaTimeUtils utils = new JodaTimeUtils(); DateTime ret = new DateTime().withTimeAtStartOfDay() .withChronology(Context.getThreadContext().getChronology()); for (final DateDefaultValues value : DateDefaultValues.values()) { if (utils.containsProperty(_parameter, value.toString())) { final String strValue = utils.getProperty(_parameter, value.toString()); switch (value) { case TODAY: ret = new DateTime().withChronology(Context.getThreadContext().getChronology()); break; case WEEKS: ret = ret.plusWeeks(Integer.valueOf(strValue)); break; case MONTHS: ret = ret.plusMonths(Integer.valueOf(strValue)); break; case YEARS: ret = ret.plusYears(Integer.valueOf(strValue)); break; case WITHDAYOFMONTH: ret = ret.withDayOfMonth(Integer.valueOf(strValue)); break; case WITHDAYOFWEEK: ret = ret.withDayOfWeek(Integer.valueOf(strValue)); break; case LASTDAYOFMONTH: ret = ret.dayOfMonth().withMaximumValue(); break; case WITHDAYOFYEAR: ret = ret.withDayOfYear(Integer.valueOf(strValue)); default: break; } } } return ret; }
From source file:org.efaps.esjp.common.uiform.Field_Base.java
License:Apache License
/** * Method to get a Datevalue for a field on create to set a more "intelligent" * value like "monday of current week" etc. * Properties:/*from ww w . j av a 2 s . co m*/ * <table> * <tr><th>Property</th><th>Value</th><th>Description</th></tr> * <tr><td>withDayOfWeek</td><td>1,2,3,4,5,6,7</td> * <td>the Integer represents on of the weekdays starting with Monday, Tuesday...</td></tr> * <tr><td>withDayOfMonth</td><td>Integer</td><td>day of month</td></tr> * <tr><td>minusDays</td><td>Integer</td><td>days to subtract</td></tr> * <tr><td>plusDays</td><td>Integer</td><td>days to add</td></tr> * <tr><td>minusWeeks</td><td>Integer</td><td>weeks to subtract</td></tr> * <tr><td>plusWeeks</td><td>Integer</td><td>weeks to add</td></tr> * </table> * * @param _parameter Parameter as passed by the eFaps API * @return ReturnValue containing the date * @throws EFapsException on error */ public Return getDefault4DateFieldValue(final Parameter _parameter) throws EFapsException { final Return ret = new Return(); final TargetMode mode = (TargetMode) _parameter.get(ParameterValues.ACCESSMODE); final Collection<TargetMode> modes = new ArrayList<>(); for (final String aMode : analyseProperty(_parameter, "TargetMode").values()) { modes.add(EnumUtils.getEnum(TargetMode.class, aMode.toUpperCase())); } if ((TargetMode.CREATE.equals(mode) || TargetMode.EDIT.equals(mode)) && (modes.isEmpty() || modes.contains(mode))) { DateTime date = new DateTime(); if (containsProperty(_parameter, "withDayOfWeek")) { final int dayOfWeek = Integer.parseInt(getProperty(_parameter, "withDayOfWeek")); date = date.withDayOfWeek(dayOfWeek); } if (containsProperty(_parameter, "withDayOfMonth")) { final int dayOfMonth = Integer.parseInt(getProperty(_parameter, "withDayOfMonth")); date = date.withDayOfMonth(dayOfMonth); } if (containsProperty(_parameter, "days")) { final int days = Integer.parseInt(getProperty(_parameter, "days")); date = date.plusDays(days); } if (containsProperty(_parameter, "weeks")) { final int weeks = Integer.parseInt(getProperty(_parameter, "weeks")); date = date.plusWeeks(weeks); } if (containsProperty(_parameter, "months")) { final int months = Integer.parseInt(getProperty(_parameter, "months")); date = date.plusMonths(months); } if (containsProperty(_parameter, "years")) { final int years = Integer.parseInt(getProperty(_parameter, "years")); date = date.plusYears(years); } ret.put(ReturnValues.VALUES, date); } return ret; }
From source file:org.fenixedu.academic.api.FenixAPIv1.java
License:Open Source License
private FenixSpace.Room getFenixRoom(Space room, java.util.Calendar rightNow) { InfoSiteRoomTimeTable bodyComponent = RoomSiteComponentBuilder.getInfoSiteRoomTimeTable(rightNow, room, null);//from w ww .j ava2 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 = newDate.toString("dd/MM/yyyy"); FenixRoomEvent roomEvent = null; if (showOccupation instanceof InfoLesson || showOccupation instanceof InfoLessonInstance) { InfoShowOccupation lesson = showOccupation; InfoExecutionCourse infoExecutionCourse = lesson.getInfoShift().getInfoDisciplinaExecucao(); String start = dataFormatHour.format(lesson.getInicio().getTime()); String end = dataFormatHour.format(lesson.getFim().getTime()); 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 = dataFormatHour.format(infoWrittenTest.getInicio().getTime()); end = dataFormatHour.format(infoWrittenTest.getFim().getTime()); 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 = dataFormatHour.format(infoGenericEvent.getInicio().getTime()); String end = dataFormatHour.format(infoGenericEvent.getFim().getTime()); 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"); } }
From source file:org.fenixedu.learning.api.EventsResource.java
License:Open Source License
private Interval getInterval(String start, String end) { DateTime beginDate;/* ww w . j ava 2 s . c o 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 = ISODateTimeFormat.date().parseLocalDate(start).toDateTimeAtStartOfDay(); endDate = ISODateTimeFormat.date().parseLocalDate(end).plusDays(1).toDateTimeAtStartOfDay() .minusMillis(1); } return new Interval(beginDate, endDate); }
From source file:org.fenixedu.spaces.domain.occupation.config.ExplicitConfigWithSettings.java
License:Open Source License
private static int getNthDayOfWeek(DateTime when) { DateTime checkpoint = when; int whenDayOfWeek = checkpoint.getDayOfWeek(); int month = checkpoint.getMonthOfYear(); checkpoint = checkpoint.withDayOfMonth(1); checkpoint = checkpoint.withDayOfWeek(whenDayOfWeek); checkpoint = checkpoint.plusWeeks(month - checkpoint.getDayOfMonth()); int i = 0;/* w ww. j a va 2 s . c o m*/ while (checkpoint.getMonthOfYear() == month && !checkpoint.isEqual(when)) { checkpoint = checkpoint.plusWeeks(1); i++; } return i; }
From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java
License:Open Source License
private int getNthDayOfWeek(DateTime when) { DateTime checkpoint = when; int whenDayOfWeek = checkpoint.getDayOfWeek(); int month = checkpoint.getMonthOfYear(); checkpoint = checkpoint.withDayOfMonth(1); checkpoint = checkpoint.withDayOfWeek(whenDayOfWeek); checkpoint = checkpoint.plusWeeks(month - checkpoint.getDayOfMonth()); int i = 0;// www . j a v a 2 s. co m while (checkpoint.getMonthOfYear() == month && !checkpoint.isEqual(when)) { checkpoint = checkpoint.plusWeeks(1); i++; } return i; }
From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java
License:Open Source License
private DateTime getNextNthdayOfWeek(DateTime when, int nthdayOfTheWeek, int dayOfTheWeek) { DateTime checkpoint = when;//from w ww .j a va2 s .co m int month = checkpoint.getMonthOfYear(); checkpoint = checkpoint.withDayOfMonth(1); checkpoint = checkpoint.plusWeeks(month - checkpoint.getMonthOfYear()); int i = nthdayOfTheWeek; if (i > 3) { DateTime lastDayOfMonth = checkpoint.dayOfMonth().withMaximumValue(); lastDayOfMonth = lastDayOfMonth.withDayOfWeek(dayOfTheWeek); return lastDayOfMonth.plusWeeks(month - lastDayOfMonth.getMonthOfYear()); } else { return checkpoint.plusWeeks(nthdayOfTheWeek); } }
From source file:org.fenixedu.spaces.domain.occupation.config.WeeklyConfig.java
License:Open Source License
@Override public List<Interval> getIntervals() { final List<Interval> intervals = new ArrayList<>(); DateTime start = getInterval().getStart(); DateTime end = getInterval().getEnd(); // adjust start date to correct day of the week int firstDayOfWeekIndex = daysOfWeek.indexOf(start.getDayOfWeek()); if (firstDayOfWeekIndex == -1) { firstDayOfWeekIndex = 0;//from www . ja v a 2 s . c om } DateTime checkpoint = start.withDayOfWeek(daysOfWeek.get(firstDayOfWeekIndex)); if (checkpoint.isBefore(start)) { checkpoint.plusWeeks(1); } int i = firstDayOfWeekIndex; while (checkpoint.isBefore(end) || checkpoint.isEqual(end)) { intervals.add(new Interval(checkpoint.withFields(getStartTime()), checkpoint.withFields(getEndTime()))); if (i == daysOfWeek.size() - 1) { i = 0; checkpoint = checkpoint.plusWeeks(getRepeatsEvery()); } else { i++; } checkpoint = checkpoint.withDayOfWeek(daysOfWeek.get(i)); } return intervals; }