Example usage for org.joda.time DateTime getDayOfWeek

List of usage examples for org.joda.time DateTime getDayOfWeek

Introduction

In this page you can find the example usage for org.joda.time DateTime getDayOfWeek.

Prototype

public int getDayOfWeek() 

Source Link

Document

Get the day of week field value.

Usage

From source file:org.kuali.kpme.tklm.time.detail.validation.TimeDetailValidationUtil.java

License:Educational Community License

public static List<String> validateSpanningWeeks(boolean spanningWeeks, DateTime startTemp, DateTime endTemp) {
    List<String> errors = new ArrayList<String>();

    if (!spanningWeeks) {
        boolean isOnlyWeekendSpan = true;
        while ((startTemp.isBefore(endTemp) || startTemp.isEqual(endTemp)) && isOnlyWeekendSpan) {
            if (startTemp.getDayOfWeek() != DateTimeConstants.SATURDAY
                    && startTemp.getDayOfWeek() != DateTimeConstants.SUNDAY) {
                isOnlyWeekendSpan = false;
            }// w w  w  .  ja  v  a 2 s . c o  m
            startTemp = startTemp.plusDays(1);
        }
        if (isOnlyWeekendSpan) {
            errors.add("Weekend day is selected, but include weekends checkbox is not checked");
        }
    }

    return errors;
}

From source file:org.kuali.kpme.tklm.time.rules.shiftdifferential.service.ShiftDifferentialRuleServiceImpl.java

License:Educational Community License

private boolean dayIsRuleActive(DateTime currentDate, ShiftDifferentialRule sdr) {
    boolean active = false;

    switch (currentDate.getDayOfWeek()) {
    case DateTimeConstants.MONDAY:
        active = sdr.isMonday();/*from  w  w w. j  a va2  s.  c  om*/
        break;
    case DateTimeConstants.TUESDAY:
        active = sdr.isTuesday();
        break;
    case DateTimeConstants.WEDNESDAY:
        active = sdr.isWednesday();
        break;
    case DateTimeConstants.THURSDAY:
        active = sdr.isThursday();
        break;
    case DateTimeConstants.FRIDAY:
        active = sdr.isFriday();
        break;
    case DateTimeConstants.SATURDAY:
        active = sdr.isSaturday();
        break;
    case DateTimeConstants.SUNDAY:
        active = sdr.isSunday();
        break;
    }

    return active;
}

From source file:org.kuali.kpme.tklm.time.rules.shiftdifferential.shift.ShiftCalendarInterval.java

License:Educational Community License

protected boolean ruleIsActiveForDay(DateTime currentDate, ShiftDifferentialRule sdr) {
    boolean active = false;

    switch (currentDate.getDayOfWeek()) {
    case DateTimeConstants.MONDAY:
        active = sdr.isMonday();//from w w  w .j a  v  a 2s  .  c o m
        break;
    case DateTimeConstants.TUESDAY:
        active = sdr.isTuesday();
        break;
    case DateTimeConstants.WEDNESDAY:
        active = sdr.isWednesday();
        break;
    case DateTimeConstants.THURSDAY:
        active = sdr.isThursday();
        break;
    case DateTimeConstants.FRIDAY:
        active = sdr.isFriday();
        break;
    case DateTimeConstants.SATURDAY:
        active = sdr.isSaturday();
        break;
    case DateTimeConstants.SUNDAY:
        active = sdr.isSunday();
        break;
    }

    return active;
}

From source file:org.kuali.kpme.tklm.time.timeblock.service.TimeBlockServiceImpl.java

License:Educational Community License

public List<TimeBlock> buildTimeBlocksSpanDates(Assignment assignment, String earnCode,
        TimesheetDocument timesheetDocument, DateTime beginDateTime, DateTime endDateTime, BigDecimal hours,
        BigDecimal amount, Boolean getClockLogCreated, Boolean getLunchDeleted, String spanningWeeks,
        String userPrincipalId) {
    DateTimeZone zone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
    DateTime beginDt = beginDateTime.withZone(zone);
    DateTime endDt = beginDt.toLocalDate().toDateTime(endDateTime.withZone(zone).toLocalTime(), zone);
    if (endDt.isBefore(beginDt))
        endDt = endDt.plusDays(1);// w ww  . ja  v a 2  s . c  o m

    List<Interval> dayInt = TKUtils.getDaySpanForCalendarEntry(timesheetDocument.getCalendarEntry());
    TimeBlock firstTimeBlock = new TimeBlock();
    List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();

    DateTime endOfFirstDay = null; // KPME-2568
    long diffInMillis = 0; // KPME-2568

    for (Interval dayIn : dayInt) {
        if (dayIn.contains(beginDt)) {
            if (dayIn.contains(endDt) || dayIn.getEnd().equals(endDt)) {
                // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list
                if (StringUtils.isEmpty(spanningWeeks)
                        && (dayIn.getStart().getDayOfWeek() == DateTimeConstants.SATURDAY
                                || dayIn.getStart().getDayOfWeek() == DateTimeConstants.SUNDAY)) {
                    // Get difference in millis for the next time block - KPME-2568
                    endOfFirstDay = endDt.withZone(zone);
                    diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis();
                } else {
                    firstTimeBlock = createTimeBlock(timesheetDocument, beginDateTime, endDt, assignment,
                            earnCode, hours, amount, false, getLunchDeleted, userPrincipalId);
                    lstTimeBlocks.add(firstTimeBlock);
                }
            } else {
                //TODO move this to prerule validation
                //throw validation error if this case met error
            }
        }
    }

    DateTime endTime = endDateTime.withZone(zone);
    if (firstTimeBlock.getEndDateTime() != null) { // KPME-2568
        endOfFirstDay = firstTimeBlock.getEndDateTime().withZone(zone);
        diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis();
    }
    DateTime currTime = beginDt.plusDays(1);
    while (currTime.isBefore(endTime) || currTime.isEqual(endTime)) {
        // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list
        if (StringUtils.isEmpty(spanningWeeks) && (currTime.getDayOfWeek() == DateTimeConstants.SATURDAY
                || currTime.getDayOfWeek() == DateTimeConstants.SUNDAY)) {
            // do nothing
        } else {
            TimeBlock tb = createTimeBlock(timesheetDocument, currTime, currTime.plus(diffInMillis), assignment,
                    earnCode, hours, amount, false, getLunchDeleted, userPrincipalId);
            lstTimeBlocks.add(tb);
        }
        currTime = currTime.plusDays(1);
    }
    return lstTimeBlocks;
}

From source file:org.mifos.application.collectionsheet.persistence.MeetingBuilder.java

License:Open Source License

public MeetingBuilder withStartDate(final DateTime withStartDate) {
    this.startDate = withStartDate.toDate();
    this.weekDay = WeekDay.getJodaWeekDay(withStartDate.getDayOfWeek());
    return this;
}

From source file:org.mifos.schedule.builder.ScheduledEventBuilder.java

License:Open Source License

protected static WeekDay dateTimeToWeekDay(final DateTime dateTime) {
    final int dayOfWeekUsingDateTimeApi = dateTime.getDayOfWeek();

    if (dayOfWeekUsingDateTimeApi == 7) {
        return WeekDay.SUNDAY;
    }//from   w  w  w . j  a v  a  2s.co m

    return WeekDay.getWeekDay(dayOfWeekUsingDateTimeApi + 1);
}

From source file:org.mifos.test.acceptance.framework.loan.CreateLoanAccountReviewInstallmentPage.java

License:Open Source License

private DateTime getValidDate(DateTime disbursalDate, int minGap, boolean isGapIsMinimumGap) {
    DateTime dateTime = disbursalDate.plusDays(minGap);
    if (dateTime.getDayOfWeek() == 7) {
        if (isGapIsMinimumGap) {
            dateTime = dateTime.plusDays(1);
        } else {//ww  w  .  j a va2 s . c  o  m
            dateTime = dateTime.minusDays(1);
        }
    }
    return dateTime;
}

From source file:org.mifos.test.acceptance.framework.loan.RedoLoanDisbursalSchedulePreviewPage.java

License:Open Source License

private DateTime getValidDate(DateTime date, int minimumGap, boolean isGapIsMinimumGap) {
    DateTime dateTime = date.plusDays(minimumGap);
    if (dateTime.getDayOfWeek() == 7) {
        if (isGapIsMinimumGap) {
            dateTime = dateTime.plusDays(1);
        } else {//from   w w  w .j av a2s . c om
            dateTime = dateTime.minusDays(1);
        }
    }
    return dateTime;
}

From source file:org.mrgeo.featurefilter.DateColumnFeatureFilter.java

License:Apache License

private boolean datePassesFilter(DateTime date, DateTime filter) {
    return ((dateFilterGranularity.equals(DateGranularity.AFTER) && date.isAfter(filter))
            || (dateFilterGranularity.equals(DateGranularity.BEFORE) && date.isBefore(filter))
            || (dateFilterGranularity.equals(DateGranularity.SAME_INSTANT) && filter.isEqual(date))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_A_MINUTE)
                    && (Minutes.minutesBetween(filter, date).getMinutes() == 0))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_AN_HOUR)
                    && (Hours.hoursBetween(filter, date).getHours() == 0))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_A_DAY)
                    && (Days.daysBetween(filter, date).getDays() == 0))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_A_MONTH)
                    && (Months.monthsBetween(filter, date).getMonths() == 0))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_A_YEAR)
                    && (Years.yearsBetween(filter, date).getYears() == 0))
            || (dateFilterGranularity.equals(DateGranularity.SAME_MINUTE_OF_ANY_HOUR)
                    && (date.getMinuteOfHour() == filter.getMinuteOfHour()))
            || (dateFilterGranularity.equals(DateGranularity.SAME_HOUR_OF_ANY_DAY)
                    && (date.getHourOfDay() == filter.getHourOfDay()))
            || (dateFilterGranularity.equals(DateGranularity.SAME_DAY_OF_ANY_WEEK)
                    && (date.getDayOfWeek() == filter.getDayOfWeek()))
            || (dateFilterGranularity.equals(DateGranularity.SAME_DAY_OF_ANY_MONTH)
                    && (date.getDayOfMonth() == filter.getDayOfMonth()))
            ||//  w  ww. j a  v a  2s  . c  o  m
            //date.getDayOfYear isn't sufficient here, b/c leap years have a different number of days
            (dateFilterGranularity.equals(DateGranularity.SAME_DAY_OF_ANY_YEAR)
                    && ((date.getDayOfMonth() == filter.getDayOfMonth())
                            && (date.getMonthOfYear() == filter.getMonthOfYear())))
            || (dateFilterGranularity.equals(DateGranularity.SAME_MONTH_OF_ANY_YEAR)
                    && (date.getMonthOfYear() == filter.getMonthOfYear())));
}

From source file:org.numenta.nupic.encoders.DateEncoder.java

License:Open Source License

/**
 * Returns an {@link TDoubleList} containing the sub-field scalar value(s) for
 * each sub-field of the inputData. To get the associated field names for each of
 * the scalar values, call getScalarNames().
 *
 * @param inputData   the input value, in this case a date object
 * @return   a list of one input double//w  w  w . j  av  a 2 s.  c  o  m
 */
public TDoubleList getScalars(DateTime inputData) {
    if (inputData == null) {
        throw new IllegalArgumentException("DateEncoder requires a valid Date object but got null");
    }

    TDoubleList values = new TDoubleArrayList();

    //Get the scalar values for each sub-field

    double timeOfDay = inputData.getHourOfDay() + inputData.getMinuteOfHour() / 60.0;

    // The day of week was 1 based, so convert to 0 based
    int dayOfWeek = inputData.getDayOfWeek() - 1; // + timeOfDay / 24.0

    if (seasonEncoder != null) {
        // The day of year was 1 based, so convert to 0 based
        double dayOfYear = inputData.getDayOfYear() - 1;
        values.add(dayOfYear);
    }

    if (dayOfWeekEncoder != null) {
        values.add(dayOfWeek);
    }

    if (weekendEncoder != null) {

        //saturday, sunday or friday evening
        boolean isWeekend = dayOfWeek == 6 || dayOfWeek == 5 || (dayOfWeek == 4 && timeOfDay > 18);

        int weekend = isWeekend ? 1 : 0;

        values.add(weekend);
    }

    if (customDaysEncoder != null) {
        boolean isCustomDays = customDaysList.contains(dayOfWeek);

        int customDay = isCustomDays ? 1 : 0;

        values.add(customDay);
    }

    if (holidayEncoder != null) {
        // A "continuous" binary value. = 1 on the holiday itself and smooth ramp
        //  0->1 on the day before the holiday and 1->0 on the day after the holiday.

        double holidayness = 0;

        for (Tuple h : holidaysList) {
            //hdate is midnight on the holiday
            DateTime hdate = new DateTime(inputData.getYear(), (int) h.get(0), (int) h.get(1), 0, 0, 0);

            if (inputData.isAfter(hdate)) {
                Duration diff = new Interval(hdate, inputData).toDuration();
                long days = diff.getStandardDays();
                if (days == 0) {
                    //return 1 on the holiday itself
                    holidayness = 1;
                    break;
                } else if (days == 1) {
                    //ramp smoothly from 1 -> 0 on the next day
                    holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0);
                    break;
                }

            } else {
                //TODO This is not the same as when date.isAfter(hdate), why?
                Duration diff = new Interval(inputData, hdate).toDuration();
                long days = diff.getStandardDays();
                if (days == 0) {
                    //ramp smoothly from 0 -> 1 on the previous day
                    holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0);
                    //TODO Why no break?
                }
            }
        }

        values.add(holidayness);
    }

    if (timeOfDayEncoder != null) {
        values.add(timeOfDay);
    }

    return values;
}