Example usage for org.joda.time DateTimeConstants SATURDAY

List of usage examples for org.joda.time DateTimeConstants SATURDAY

Introduction

In this page you can find the example usage for org.joda.time DateTimeConstants SATURDAY.

Prototype

int SATURDAY

To view the source code for org.joda.time DateTimeConstants SATURDAY.

Click Source Link

Document

Constant (6) representing Saturday, the sixth day of the week (ISO)

Usage

From source file:calculadora.JanelaTrabalho.java

License:Apache License

@Override
public boolean estaDentro(DateTime data) {
    if (data.getDayOfWeek() != DateTimeConstants.SATURDAY && data.getDayOfWeek() != DateTimeConstants.SUNDAY) {
        int h = data.getHourOfDay();

        for (Periodo p : periodos) {
            if (h >= p.getInicial() && h < p.getFinall()) {
                return true;
            }/*from w w w.ja  v a2s  .c  o  m*/
        }
    }
    return false;
}

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 ww w.  j  a v a2 s .  co  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);/*from w  ww.ja v  a2 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);/* www  .  j a  v  a2s.  co  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  w w.  j  a  v a  2 s  .c om*/
        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 w w  .j a  v  a 2  s  .  co 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.bgh.myopeninvoice.db.model.TimeSheetEntity.java

License:Apache License

@Transient
public Boolean getWeekend() {
    if (isWeekend == null) {
        DateTime d = new DateTime(itemDate);
        isWeekend = d.getDayOfWeek() == DateTimeConstants.SATURDAY
                || d.getDayOfWeek() == DateTimeConstants.SUNDAY ? Boolean.TRUE : Boolean.FALSE;
    }//from  w w  w .  ja  va  2  s .c o m
    return isWeekend;
}

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.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

private DateTime scheduleWeekday(DateTime now) {
    DateTime nowMidnight = now.toDateMidnight().toDateTime();
    if (nowMidnight.getDayOfWeek() < DateTimeConstants.SATURDAY) { // jodatime starts with Monday = 0
        DateTime nextTimeToday = getNextTimeToday(now, nowMidnight);
        if (nextTimeToday != null) {
            return nextTimeToday;
        }//  w w  w  .j  a v  a2s .  co  m
    }
    DateTime nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
    return getFirstScheduledTimeOnDay(nextDay);
}

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

License:Open Source License

public static boolean isWeekend(int dayOfWeek) {
    return dayOfWeek == DateTimeConstants.SATURDAY || dayOfWeek == DateTimeConstants.SUNDAY;
}