List of usage examples for org.joda.time DateTimeConstants MONDAY
int MONDAY
To view the source code for org.joda.time DateTimeConstants MONDAY.
Click Source Link
From source file:cl.usach.managedbeans.TrabajoSemanalManagedBean.java
public List<Semana> buscarSemanas(Date datei, Date datef) { DateTime fechai = new DateTime(datei); DateTime fechaf = new DateTime(datef); LocalDate lunesI = fechai.toLocalDate().withDayOfWeek(DateTimeConstants.MONDAY); LocalDate domingoF = fechaf.toLocalDate().withDayOfWeek(DateTimeConstants.SUNDAY); List<Semana> semanas = new ArrayList<>(); DateTime i = lunesI.toDateTimeAtStartOfDay(); while (i.isBefore(domingoF.toDateTimeAtStartOfDay())) { DateTime domingoi = i.toLocalDate().withDayOfWeek(DateTimeConstants.SUNDAY).toDateTimeAtStartOfDay(); domingoi = domingoi.plusHours(23).plusMinutes(59).plusSeconds(59); semanas.add(new Semana(i.toDate(), domingoi.toDate())); i = i.plusWeeks(1);/*from w w w .j ava 2s.c om*/ } return semanas; }
From source file:com.axelor.apps.base.service.scheduler.SchedulerService.java
License:Open Source License
/** * Mthode qui dtermine la prochaine date d'xcution d'un planificateur pour un rythme hebdomadaire * * @param scheduler/*from w w w .j ava 2s . c o m*/ * Instance de planificateur * @param date * Derniere date d'xcution thorique * * @return LocalDate * Prochaine date d'xcution */ private LocalDate getWeeklyComputeDate(Scheduler scheduler, LocalDate date) { int weekDay = 0; if (scheduler.getMonday()) weekDay = DateTimeConstants.MONDAY; else if (scheduler.getTuesday()) weekDay = DateTimeConstants.TUESDAY; else if (scheduler.getWednesday()) weekDay = DateTimeConstants.WEDNESDAY; else if (scheduler.getThursday()) weekDay = DateTimeConstants.THURSDAY; else if (scheduler.getFriday()) weekDay = DateTimeConstants.FRIDAY; else if (scheduler.getSaturday()) weekDay = DateTimeConstants.SATURDAY; else if (scheduler.getSunday()) weekDay = DateTimeConstants.SUNDAY; if (weekDay == 0) weekDay = 1; return date.plusWeeks(scheduler.getWeekWeekly()).withDayOfWeek(weekDay); }
From source file:com.axelor.apps.crm.web.EventController.java
License:Open Source License
@Transactional public void generateRecurrentEvents(ActionRequest request, ActionResponse response) throws AxelorException { Long eventId = new Long(request.getContext().get("_idEvent").toString()); Event event = eventRepo.find(eventId); RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class); RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class); conf = confRepo.save(conf);/* ww w . j a v a 2 s .c o m*/ event.setRecurrenceConfiguration(conf); event = eventRepo.save(event); if (request.getContext().get("recurrenceType") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE)), IException.CONFIGURATION_ERROR); } int recurrenceType = new Integer(request.getContext().get("recurrenceType").toString()); if (request.getContext().get("periodicity") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } int periodicity = new Integer(request.getContext().get("periodicity").toString()); if (periodicity < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } boolean monday = (boolean) request.getContext().get("monday"); boolean tuesday = (boolean) request.getContext().get("tuesday"); boolean wednesday = (boolean) request.getContext().get("wednesday"); boolean thursday = (boolean) request.getContext().get("thursday"); boolean friday = (boolean) request.getContext().get("friday"); boolean saturday = (boolean) request.getContext().get("saturday"); boolean sunday = (boolean) request.getContext().get("sunday"); Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>(); if (recurrenceType == 2) { daysMap.put(DateTimeConstants.MONDAY, monday); daysMap.put(DateTimeConstants.TUESDAY, tuesday); daysMap.put(DateTimeConstants.WEDNESDAY, wednesday); daysMap.put(DateTimeConstants.THURSDAY, thursday); daysMap.put(DateTimeConstants.FRIDAY, friday); daysMap.put(DateTimeConstants.SATURDAY, saturday); daysMap.put(DateTimeConstants.SUNDAY, sunday); for (Integer day : daysMap.keySet()) { if (daysMap.get(day)) { daysCheckedMap.put(day, daysMap.get(day)); } } if (daysMap.isEmpty()) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED)), IException.CONFIGURATION_ERROR); } } int monthRepeatType = new Integer(request.getContext().get("monthRepeatType").toString()); int endType = new Integer(request.getContext().get("endType").toString()); int repetitionsNumber = 0; if (endType == 1) { if (request.getContext().get("repetitionsNumber") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } repetitionsNumber = new Integer(request.getContext().get("repetitionsNumber").toString()); if (repetitionsNumber < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } } LocalDate endDate = new LocalDate(); if (endType == 2) { if (request.getContext().get("endDate") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } endDate = new LocalDate(request.getContext().get("endDate").toString()); if (endDate.isBefore(event.getStartDateTime()) && endDate.isEqual(event.getStartDateTime())) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } } switch (recurrenceType) { case 1: eventService.addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate); break; case 2: eventService.addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap); break; case 3: eventService.addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType); break; case 4: eventService.addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate); break; default: break; } response.setCanClose(true); response.setReload(true); }
From source file:com.axelor.apps.crm.web.EventController.java
License:Open Source License
@Transactional public void changeAll(ActionRequest request, ActionResponse response) throws AxelorException { Long eventId = new Long(request.getContext().get("_idEvent").toString()); Event event = eventRepo.find(eventId); Event child = eventRepo.all().filter("self.parentEvent.id = ?1", event.getId()).fetchOne(); Event parent = event.getParentEvent(); child.setParentEvent(null);// w ww . j av a2 s. c o m Event eventDeleted = child; child = eventRepo.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne(); while (child != null) { child.setParentEvent(null); eventRepo.remove(eventDeleted); eventDeleted = child; child = eventRepo.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne(); } while (parent != null) { Event nextParent = parent.getParentEvent(); eventRepo.remove(parent); parent = nextParent; } RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class); RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class); conf = confRepo.save(conf); event.setRecurrenceConfiguration(conf); event = eventRepo.save(event); if (conf.getRecurrenceType() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE)), IException.CONFIGURATION_ERROR); } int recurrenceType = conf.getRecurrenceType(); if (conf.getPeriodicity() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } int periodicity = conf.getPeriodicity(); if (periodicity < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } boolean monday = conf.getMonday(); boolean tuesday = conf.getTuesday(); boolean wednesday = conf.getWednesday(); boolean thursday = conf.getThursday(); boolean friday = conf.getFriday(); boolean saturday = conf.getSaturday(); boolean sunday = conf.getSunday(); Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>(); if (recurrenceType == 2) { daysMap.put(DateTimeConstants.MONDAY, monday); daysMap.put(DateTimeConstants.TUESDAY, tuesday); daysMap.put(DateTimeConstants.WEDNESDAY, wednesday); daysMap.put(DateTimeConstants.THURSDAY, thursday); daysMap.put(DateTimeConstants.FRIDAY, friday); daysMap.put(DateTimeConstants.SATURDAY, saturday); daysMap.put(DateTimeConstants.SUNDAY, sunday); for (Integer day : daysMap.keySet()) { if (daysMap.get(day)) { daysCheckedMap.put(day, daysMap.get(day)); } } if (daysMap.isEmpty()) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED)), IException.CONFIGURATION_ERROR); } } int monthRepeatType = conf.getMonthRepeatType(); int endType = conf.getEndType(); int repetitionsNumber = 0; if (endType == 1) { if (conf.getRepetitionsNumber() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } repetitionsNumber = conf.getRepetitionsNumber(); if (repetitionsNumber < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } } LocalDate endDate = new LocalDate(); if (endType == 2) { if (conf.getEndDate() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } endDate = new LocalDate(conf.getEndDate()); if (endDate.isBefore(event.getStartDateTime()) && endDate.isEqual(event.getStartDateTime())) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } } switch (recurrenceType) { case 1: eventService.addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate); break; case 2: eventService.addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap); break; case 3: eventService.addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType); break; case 4: eventService.addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate); break; default: break; } response.setCanClose(true); response.setReload(true); }
From source file:com.axelor.apps.project.service.ProjectPlanningService.java
License:Open Source License
public void getTasksForUser(ActionRequest request, ActionResponse response) { List<Map<String, String>> dataList = new ArrayList<Map<String, String>>(); try {/*from w ww.j a v a 2 s. c o m*/ LocalDate todayDate = Beans.get(GeneralService.class).getTodayDate(); List<ProjectPlanningLine> linesList = Beans.get(ProjectPlanningLineRepository.class).all() .filter("self.user.id = ?1 AND self.year >= ?2 AND self.week >= ?3", AuthUtils.getUser().getId(), todayDate.getYear(), todayDate.getWeekOfWeekyear()) .fetch(); for (ProjectPlanningLine line : linesList) { if (line.getMonday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.MONDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getMonday().toString()); dataList.add(map); } } if (line.getTuesday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.TUESDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getTuesday().toString()); dataList.add(map); } } if (line.getWednesday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.WEDNESDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getWednesday().toString()); dataList.add(map); } } if (line.getThursday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.THURSDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getThursday().toString()); dataList.add(map); } } if (line.getFriday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.FRIDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getFriday().toString()); dataList.add(map); } } if (line.getSaturday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.SATURDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getSaturday().toString()); dataList.add(map); } } if (line.getSunday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.SUNDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getSunday().toString()); dataList.add(map); } } } response.setData(dataList); } catch (Exception e) { response.setStatus(-1); response.setError(e.getMessage()); } }
From source file:com.battlelancer.seriesguide.util.TimeTools.java
License:Apache License
/** * Converts US week day string to {@link org.joda.time.DateTimeConstants} day. * * <p> Returns -1 if no conversion is possible and 0 if it is "Daily". *///w ww. ja v a 2s . c o m public static int parseShowReleaseWeekDay(String day) { if (day == null || day.length() == 0) { return -1; } // catch Monday through Sunday switch (day) { case "Monday": return DateTimeConstants.MONDAY; case "Tuesday": return DateTimeConstants.TUESDAY; case "Wednesday": return DateTimeConstants.WEDNESDAY; case "Thursday": return DateTimeConstants.THURSDAY; case "Friday": return DateTimeConstants.FRIDAY; case "Saturday": return DateTimeConstants.SATURDAY; case "Sunday": return DateTimeConstants.SUNDAY; case "Daily": return 0; } // no match return -1; }
From source file:com.effektif.workflow.api.model.NextRelativeTime.java
License:Apache License
public static String dayOfWeekToString(Integer dayOfWeek) { if (dayOfWeek == null) return "unspecified day"; else if (dayOfWeek == DateTimeConstants.MONDAY) return "Monday"; // 1 else if (dayOfWeek == DateTimeConstants.TUESDAY) return "Tuesday"; // 2 else if (dayOfWeek == DateTimeConstants.WEDNESDAY) return "Wednesday"; // 3 else if (dayOfWeek == DateTimeConstants.THURSDAY) return "Thursday"; // 4 else if (dayOfWeek == DateTimeConstants.FRIDAY) return "Friday"; // 5 else if (dayOfWeek == DateTimeConstants.SATURDAY) return "Saturday"; // 6 else if (dayOfWeek == DateTimeConstants.SUNDAY) return "Sunday"; // 7 return "invalid day of the week " + dayOfWeek; }
From source file:com.epam.ta.reportportal.core.project.impl.ProjectInfoWidgetDataConverter.java
License:Open Source License
/** * <b>Quantity of Launches</b> project info widget content * /* w w w .j a v a2 s . co m*/ * @param initial * @param interval * @return */ public Map<String, List<ChartObject>> getLaunchesQuantity(List<Launch> initial, InfoInterval interval) { final String START_PERIOD = "start"; final String END_PERIOD = "end"; final String COUNT = "count"; final String INTERVAL = "interval"; HashMap<String, List<ChartObject>> result = new HashMap<>(); if (initial.isEmpty()) { return result; } ProjectInfoGroup criteria = grouping.get(interval); Map<String, List<Launch>> grouped = groupBy(initial, criteria); for (Entry<String, List<Launch>> entry : grouped.entrySet()) { List<Launch> launches = entry.getValue(); Integer count = null != launches ? launches.size() : 0; ChartObject group = new ChartObject(); Map<String, String> values = new HashMap<>(); values.put(COUNT, String.valueOf(count)); values.put(INTERVAL, interval.getInterval()); if (criteria != BY_DAY) { DateTime parse = DateTime.parse(entry.getKey()); // TODO remove Yoda time. replace with JDK8 values.put(START_PERIOD, parse.withDayOfWeek(DateTimeConstants.MONDAY).toString("yyy-MM-dd")); values.put(END_PERIOD, parse.withDayOfWeek(DateTimeConstants.SUNDAY).toString("yyy-MM-dd")); } else { values.put(START_PERIOD, entry.getKey()); } group.setName("Number of launches"); group.setValues(values); result.put(entry.getKey(), Collections.singletonList(group)); } return result; }
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 www .j a v a 2 s. co m return mondayOfWeek; }
From source file:com.google.sampling.experiential.server.DSQueryBuilder.java
License:Open Source License
private static DateTime getMondayOfWeekEnclosing(DateTime today) { return today.dayOfWeek().setCopy(DateTimeConstants.MONDAY); }