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.jruby.util.RubyDateFormatter.java

License:LGPL

public ByteList formatToByteList(List<Token> compiledPattern, DateTime dt, long nsec, IRubyObject sub_millis) {
    RubyTimeOutputFormatter formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER;
    ByteList toAppendTo = new ByteList();

    for (Token token : compiledPattern) {
        String output = null;//from  w  w  w  . j a v  a 2s  .c  o  m
        long value = 0;
        FieldType type = TEXT;
        Format format = token.getFormat();

        switch (format) {
        case FORMAT_ENCODING:
            toAppendTo.setEncoding((Encoding) token.getData());
            continue; // go to next token
        case FORMAT_OUTPUT:
            formatter = (RubyTimeOutputFormatter) token.getData();
            continue; // go to next token
        case FORMAT_STRING:
            output = token.getData().toString();
            break;
        case FORMAT_WEEK_LONG:
            // This is GROSS, but Java API's aren't ISO 8601 compliant at all
            int v = (dt.getDayOfWeek() + 1) % 8;
            if (v == 0) {
                v++;
            }
            output = FORMAT_SYMBOLS.getWeekdays()[v];
            break;
        case FORMAT_WEEK_SHORT:
            // This is GROSS, but Java API's aren't ISO 8601 compliant at all
            v = (dt.getDayOfWeek() + 1) % 8;
            if (v == 0) {
                v++;
            }
            output = FORMAT_SYMBOLS.getShortWeekdays()[v];
            break;
        case FORMAT_MONTH_LONG:
            output = FORMAT_SYMBOLS.getMonths()[dt.getMonthOfYear() - 1];
            break;
        case FORMAT_MONTH_SHORT:
            output = FORMAT_SYMBOLS.getShortMonths()[dt.getMonthOfYear() - 1];
            break;
        case FORMAT_DAY:
            type = NUMERIC2;
            value = dt.getDayOfMonth();
            break;
        case FORMAT_DAY_S:
            type = NUMERIC2BLANK;
            value = dt.getDayOfMonth();
            break;
        case FORMAT_HOUR:
            type = NUMERIC2;
            value = dt.getHourOfDay();
            break;
        case FORMAT_HOUR_BLANK:
            type = NUMERIC2BLANK;
            value = dt.getHourOfDay();
            break;
        case FORMAT_HOUR_M:
        case FORMAT_HOUR_S:
            value = dt.getHourOfDay();
            if (value == 0) {
                value = 12;
            } else if (value > 12) {
                value -= 12;
            }

            type = (format == Format.FORMAT_HOUR_M) ? NUMERIC2 : NUMERIC2BLANK;
            break;
        case FORMAT_DAY_YEAR:
            type = NUMERIC3;
            value = dt.getDayOfYear();
            break;
        case FORMAT_MINUTES:
            type = NUMERIC2;
            value = dt.getMinuteOfHour();
            break;
        case FORMAT_MONTH:
            type = NUMERIC2;
            value = dt.getMonthOfYear();
            break;
        case FORMAT_MERIDIAN:
            output = dt.getHourOfDay() < 12 ? "AM" : "PM";
            break;
        case FORMAT_MERIDIAN_LOWER_CASE:
            output = dt.getHourOfDay() < 12 ? "am" : "pm";
            break;
        case FORMAT_SECONDS:
            type = NUMERIC2;
            value = dt.getSecondOfMinute();
            break;
        case FORMAT_WEEK_YEAR_M:
            type = NUMERIC2;
            value = formatWeekYear(dt, java.util.Calendar.MONDAY);
            break;
        case FORMAT_WEEK_YEAR_S:
            type = NUMERIC2;
            value = formatWeekYear(dt, java.util.Calendar.SUNDAY);
            break;
        case FORMAT_DAY_WEEK:
            type = NUMERIC;
            value = dt.getDayOfWeek() % 7;
            break;
        case FORMAT_DAY_WEEK2:
            type = NUMERIC;
            value = dt.getDayOfWeek();
            break;
        case FORMAT_YEAR_LONG:
            value = year(dt, dt.getYear());
            type = (value >= 0) ? NUMERIC4 : NUMERIC5;
            break;
        case FORMAT_YEAR_SHORT:
            type = NUMERIC2;
            value = year(dt, dt.getYear()) % 100;
            break;
        case FORMAT_COLON_ZONE_OFF:
            // custom logic because this is so weird
            value = dt.getZone().getOffset(dt.getMillis()) / 1000;
            int colons = (Integer) token.getData();
            output = formatZone(colons, (int) value, formatter);
            break;
        case FORMAT_ZONE_ID:
            output = dt.getZone().getShortName(dt.getMillis());
            break;
        case FORMAT_CENTURY:
            type = NUMERIC;
            value = year(dt, dt.getYear()) / 100;
            break;
        case FORMAT_EPOCH:
            type = NUMERIC;
            value = dt.getMillis() / 1000;
            break;
        case FORMAT_WEEK_WEEKYEAR:
            type = NUMERIC2;
            value = dt.getWeekOfWeekyear();
            break;
        case FORMAT_MILLISEC:
        case FORMAT_NANOSEC:
            int defaultWidth = (format == Format.FORMAT_NANOSEC) ? 9 : 3;
            int width = formatter.getWidth(defaultWidth);

            output = RubyTimeOutputFormatter.formatNumber(dt.getMillisOfSecond(), 3, '0');
            if (width > 3) {
                if (sub_millis == null || sub_millis.isNil()) { // Time
                    output += RubyTimeOutputFormatter.formatNumber(nsec, 6, '0');
                } else { // Date, DateTime
                    int prec = width - 3;
                    IRubyObject power = context.runtime.newFixnum(10).callMethod("**",
                            context.runtime.newFixnum(prec));
                    IRubyObject truncated = sub_millis.callMethod(context, "numerator").callMethod(context, "*",
                            power);
                    truncated = truncated.callMethod(context, "/",
                            sub_millis.callMethod(context, "denominator"));
                    long decimals = truncated.convertToInteger().getLongValue();
                    output += RubyTimeOutputFormatter.formatNumber(decimals, prec, '0');
                }
            }

            if (width < output.length()) {
                output = output.substring(0, width);
            } else {
                // Not enough precision, fill with 0
                while (output.length() < width)
                    output += "0";
            }
            formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; // no more formatting
            break;
        case FORMAT_WEEKYEAR:
            value = year(dt, dt.getWeekyear());
            type = (value >= 0) ? NUMERIC4 : NUMERIC5;
            break;
        case FORMAT_WEEKYEAR_SHORT:
            type = NUMERIC2;
            value = year(dt, dt.getWeekyear()) % 100;
            break;
        case FORMAT_MICROSEC_EPOCH:
            // only available for Date
            type = NUMERIC;
            value = dt.getMillis();
            break;
        case FORMAT_SPECIAL:
            throw new Error("FORMAT_SPECIAL is a special token only for the lexer.");
        }

        output = formatter.format(output, value, type);
        // reset formatter
        formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER;

        toAppendTo.append(output
                .getBytes(context.runtime.getEncodingService().charsetForEncoding(toAppendTo.getEncoding())));
    }

    return toAppendTo;
}

From source file:org.jtotus.common.DayisHoliday.java

License:Open Source License

public static boolean isHoliday(DateTime date) {

    if (date == null || date.getDayOfWeek() == DateTimeConstants.SATURDAY
            || date.getDayOfWeek() == DateTimeConstants.SUNDAY) {
        return true;
    }//from  www.j av  a2 s.com

    //int toSearch =  date.get(Calendar.DATE)*1000000+(date.get(Calendar.MONTH)+1)*10000+date.get(Calendar.YEAR);
    int toSearch = date.getDayOfMonth() * 1000000 + date.getMonthOfYear() * 10000 + date.getYear();
    //System.out.printf("To search:%d == %d:%d:%d\n", toSearch, date.get(Calendar.DATE), date.get(Calendar.MONTH)+1, date.get(Calendar.YEAR));
    for (int day : days) {
        if (day == toSearch) {
            return true;
        }
    }
    return false;
}

From source file:org.juliocesarfx.Inicio.java

/**
 * Creates new form Inicio//  w w w  .  j  a  v  a2s .c o m
 */
public Inicio() {
    initComponents();
    DateTime dt = new DateTime(new java.util.Date());
    jLabel1.setText("" + dt.getDayOfWeek());
}

From source file:org.kuali.kpme.core.util.TKUtils.java

License:Educational Community License

public static List<Interval> getFullWeekDaySpanForCalendarEntry(CalendarEntry calendarEntry,
        DateTimeZone timeZone) {/*from w w  w  . j a  va 2s. c  om*/
    DateTime beginDateTime = calendarEntry.getBeginPeriodLocalDateTime().toDateTime(timeZone);
    DateTime endDateTime = calendarEntry.getEndPeriodLocalDateTime().toDateTime(timeZone);

    List<Interval> dayIntervals = new ArrayList<Interval>();

    DateTime currDateTime = beginDateTime;
    if (beginDateTime.getDayOfWeek() != 7) {
        currDateTime = beginDateTime.plusDays(0 - beginDateTime.getDayOfWeek());
    }

    int afterEndDate = 6 - endDateTime.getDayOfWeek();
    if (endDateTime.getDayOfWeek() == 7 && endDateTime.getHourOfDay() != 0) {
        afterEndDate = 6;
    }
    if (endDateTime.getHourOfDay() == 0) {
        afterEndDate += 1;
    }
    DateTime aDate = endDateTime.plusDays(afterEndDate);
    while (currDateTime.isBefore(aDate)) {
        DateTime prevDateTime = currDateTime;
        currDateTime = currDateTime.plusDays(1);
        Interval daySpan = new Interval(prevDateTime, currDateTime);
        dayIntervals.add(daySpan);
    }

    return dayIntervals;
}

From source file:org.kuali.kpme.core.util.TKUtils.java

License:Educational Community License

public static boolean isWeekend(DateTime date) {
    return date.getDayOfWeek() == DateTimeConstants.SATURDAY || date.getDayOfWeek() == DateTimeConstants.SUNDAY;
}

From source file:org.kuali.kpme.tklm.common.CalendarValidationUtil.java

License:Educational Community License

public static List<String> validateSpanningWeeks(DateTime startDate, DateTime endDate) {
    List<String> errors = new ArrayList<String>();

    boolean isOnlyWeekendSpan = true;
    while ((startDate.isBefore(endDate) || startDate.isEqual(endDate)) && isOnlyWeekendSpan) {
        if (startDate.getDayOfWeek() != DateTimeConstants.SATURDAY
                && startDate.getDayOfWeek() != DateTimeConstants.SUNDAY) {
            isOnlyWeekendSpan = false;//from   w w w.j ava 2 s  . co  m
        }
        startDate = startDate.plusDays(1);
    }
    if (isOnlyWeekendSpan) {
        errors.add("Weekend day is selected, but include weekends checkbox is not checked"); //errorMessages
    }

    return errors;
}

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 va 2 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.kuali.kpme.tklm.leave.calendar.LeaveCalendar.java

License:Educational Community License

public LeaveCalendar(String principalId, CalendarEntry calendarEntry, List<String> assignmentKeys) {
    super(calendarEntry);

    DateTime currentDisplayDateTime = getBeginDateTime();
    DateTime endDisplayDateTime = getEndDateTime();

    // Fill in the days if the first day or end day is in the middle of the week
    if (currentDisplayDateTime.getDayOfWeek() != DateTimeConstants.SUNDAY) {
        currentDisplayDateTime = currentDisplayDateTime.minusDays(currentDisplayDateTime.getDayOfWeek());
    }/*from w  w  w  .jav  a  2  s  .co m*/
    if (endDisplayDateTime.getDayOfWeek() != DateTimeConstants.SATURDAY) {
        endDisplayDateTime = endDisplayDateTime
                .plusDays(DateTimeConstants.SATURDAY - endDisplayDateTime.getDayOfWeek());
    }

    LeaveCalendarWeek leaveCalendarWeek = new LeaveCalendarWeek();
    Integer dayNumber = 0;
    List<LeaveBlock> blocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principalId,
            calendarEntry.getBeginPeriodFullDateTime().toLocalDate(),
            calendarEntry.getEndPeriodFullDateTime().toLocalDate());
    Map<String, List<LeaveBlock>> leaveBlockMap = new HashMap<String, List<LeaveBlock>>();
    for (LeaveBlock lb : blocks) {
        String key = lb.getLeaveLocalDate().toString();
        if (leaveBlockMap.containsKey(key)) {
            leaveBlockMap.get(key).add(lb);
        } else {
            leaveBlockMap.put(key, createNewLeaveBlockList(lb));
        }
    }

    //KPME-2560 If leave calendar document is final status, then User wont be able to add leave blocks to the calendar. 
    Boolean dayEditableFlag = true;
    LeaveCalendarDocumentHeader header = LmServiceLocator.getLeaveCalendarDocumentHeaderService()
            .getDocumentHeader(principalId, calendarEntry.getBeginPeriodFullDateTime(),
                    calendarEntry.getEndPeriodFullDateTime());
    if (header != null && header.getDocumentStatus().equals(HrConstants.ROUTE_STATUS.FINAL))
        dayEditableFlag = false;

    while (currentDisplayDateTime.isBefore(endDisplayDateTime)
            || currentDisplayDateTime.isEqual(endDisplayDateTime)) {
        LeaveCalendarDay leaveCalendarDay = new LeaveCalendarDay();

        // If the day is not within the current pay period, mark them as read only (gray)
        if (currentDisplayDateTime.isBefore(getBeginDateTime())
                || currentDisplayDateTime.isEqual(getEndDateTime())
                || currentDisplayDateTime.isAfter(getEndDateTime())) {
            leaveCalendarDay.setGray(true);
        } else {
            // This is for the div id of the days on the calendar.
            // It creates a day id like day_11/01/2011 which will make day parsing easier in the javascript.
            //                leaveCalendarDay.setDayNumberDelta(currDateTime.toString(HrConstants.DT_BASIC_DATE_FORMAT));
            //                leaveCalendarDay.setDayNumberDelta(currDateTime.getDayOfMonth());
            leaveCalendarDay.setDayNumberDelta(dayNumber);

            LocalDate leaveDate = currentDisplayDateTime.toLocalDate();
            List<LeaveBlock> lbs = leaveBlockMap.get(currentDisplayDateTime.toLocalDate().toString());
            if (lbs == null) {
                lbs = Collections.emptyList();
            }
            // use given assignmentKeys to control leave blocks displayed on the calendar
            if (CollectionUtils.isNotEmpty(lbs) && CollectionUtils.isNotEmpty(assignmentKeys)) {
                List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService()
                        .filterLeaveBlocksForLeaveCalendar(lbs, assignmentKeys);
                leaveCalendarDay.setLeaveBlocks(leaveBlocks);
            } else {
                leaveCalendarDay.setLeaveBlocks(lbs);
            }

            if (HrServiceLocator.getHRPermissionService().canViewLeaveTabsWithNEStatus()) {
                TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService()
                        .getDocumentHeaderForDate(principalId, leaveDate.toDateTimeAtStartOfDay());
                if (tdh != null) {
                    if (DateUtils.isSameDay(leaveDate.toDate(), tdh.getEndDate())
                            || leaveDate.isAfter(LocalDate.fromDateFields(tdh.getEndDate()))) {
                        leaveCalendarDay.setDayEditable(true);
                    }
                } else {
                    leaveCalendarDay.setDayEditable(true);
                }
            } else {
                leaveCalendarDay.setDayEditable(true);
            }
            //KPME-2560 If leave calendar document is final status, then User wont be able to add leave blocks to the calendar. 
            if (!dayEditableFlag)
                leaveCalendarDay.setDayEditable(false);

            dayNumber++;
        }
        leaveCalendarDay.setDayNumberString(currentDisplayDateTime.dayOfMonth().getAsShortText());
        leaveCalendarDay.setDateString(currentDisplayDateTime.toString(HrConstants.DT_BASIC_DATE_FORMAT));

        leaveCalendarWeek.getDays().add(leaveCalendarDay);

        if (leaveCalendarWeek.getDays().size() == DateTimeConstants.DAYS_PER_WEEK) {
            getWeeks().add(leaveCalendarWeek);
            leaveCalendarWeek = new LeaveCalendarWeek();
        }

        currentDisplayDateTime = currentDisplayDateTime.plusDays(1);
    }

    if (!leaveCalendarWeek.getDays().isEmpty()) {
        getWeeks().add(leaveCalendarWeek);
    }

    boolean isPlanningCal = LmServiceLocator.getLeaveCalendarService().isLeavePlanningCalendar(principalId,
            calendarEntry.getBeginPeriodFullDateTime().toLocalDate(),
            calendarEntry.getEndPeriodFullDateTime().toLocalDate());
    Map<String, String> earnCodes = HrServiceLocator.getEarnCodeService().getEarnCodesForDisplay(principalId,
            isPlanningCal);
    setEarnCodeList(earnCodes);
}

From source file:org.kuali.kpme.tklm.leave.calendar.LeaveRequestCalendar.java

License:Educational Community License

public LeaveRequestCalendar(DateTime beginDateTime, DateTime endDateTime,
        Map<String, List<LeaveRequestDocument>> leaveReqDocsMap, Map<String, List<LeaveBlock>> leaveBlocksMap,
        Map<String, List<LeaveBlockHistory>> disapprovedLBMap, String calendarType) {
    this.calendarType = calendarType;
    setBeginDateTime(beginDateTime);/*from  w w  w. j a  va2 s .co  m*/
    setEndDateTime(endDateTime);

    DateTime currentDisplayDateTime = new DateTime(beginDateTime.getMillis());
    DateTime endDisplayDateTime = new DateTime(endDateTime.getMillis());

    // Fill in the days if the first day or end day is in the middle of the week
    if (currentDisplayDateTime.getDayOfWeek() != DateTimeConstants.SUNDAY) {
        currentDisplayDateTime = currentDisplayDateTime.minusDays(currentDisplayDateTime.getDayOfWeek());
    }
    if (endDisplayDateTime.getDayOfWeek() != DateTimeConstants.SATURDAY) {
        endDisplayDateTime = endDisplayDateTime
                .plusDays(DateTimeConstants.SATURDAY - endDisplayDateTime.getDayOfWeek());
    }

    LeaveRequestCalendarWeek leaveReqCalendarWeek = new LeaveRequestCalendarWeek();
    Integer dayNumber = 0;

    while (currentDisplayDateTime.isBefore(endDisplayDateTime)
            || currentDisplayDateTime.isEqual(endDisplayDateTime)) {
        LeaveRequestCalendarDay leaveReqCalendarDay = new LeaveRequestCalendarDay();

        // If the day is not within the current pay period, mark them as read only (gray)
        if (StringUtils.equalsIgnoreCase("M", calendarType)
                && (currentDisplayDateTime.isBefore(getBeginDateTime())
                        || currentDisplayDateTime.isEqual(getEndDateTime())
                        || currentDisplayDateTime.isAfter(getEndDateTime()))) {
            leaveReqCalendarDay.setGray(true);
        } else {
            // This is for the div id of the days on the calendar.
            // It creates a day id like day_11/01/2011 which will make day parsing easier in the javascript.
            leaveReqCalendarDay.setDayNumberDelta(dayNumber);

            List<LeaveRequestDocument> reqDocs = leaveReqDocsMap
                    .get(currentDisplayDateTime.toLocalDate().toString());
            List<LeaveBlock> leaveBlocks = leaveBlocksMap.get(currentDisplayDateTime.toLocalDate().toString());
            List<LeaveBlockHistory> disapprovedBlocks = disapprovedLBMap
                    .get(currentDisplayDateTime.toLocalDate().toString());
            List<LeaveRequestApprovalRow> rowList = new ArrayList<LeaveRequestApprovalRow>();
            if (reqDocs == null) {
                reqDocs = Collections.emptyList();
            }
            if (leaveBlocks == null) {
                leaveBlocks = Collections.emptyList();
            }
            List<String> leaveBlockIds = new ArrayList<String>();
            if (!reqDocs.isEmpty()) {
                for (LeaveRequestDocument lrd : reqDocs) {
                    LeaveBlock lb = lrd.getLeaveBlock();
                    leaveBlockIds.add(lb.getLmLeaveBlockId());
                    String principalId = lb.getPrincipalId();
                    LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow();
                    // Set Employee Name 
                    EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService()
                            .getDefaultNamesForPrincipalId(principalId);
                    if (entityNamePrincipalName != null) {
                        aRow.setPrincipalId(principalId);
                        aRow.setEmployeeName(
                                entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY
                                        : entityNamePrincipalName.getDefaultName().getCompositeName());
                    }
                    aRow.setLeaveRequestDocId(lrd.getDocumentNumber());
                    aRow.setLeaveCode(lb.getEarnCode());
                    aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate()));
                    aRow.setRequestedHours(lb.getLeaveAmount().toString());
                    aRow.setDescription(
                            lrd.getDescription() == null ? lb.getDescription() : lrd.getDescription());
                    aRow.setAssignmentTitle(lb.getAssignmentTitle());
                    aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase());
                    rowList.add(aRow);
                }
            }

            if (!leaveBlocks.isEmpty()) {
                for (LeaveBlock lb : leaveBlocks) {
                    if (!leaveBlockIds.contains(lb.getLmLeaveBlockId())) {
                        String principalId = lb.getPrincipalId();
                        LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow();
                        // Set Employee Name 
                        EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator
                                .getIdentityService().getDefaultNamesForPrincipalId(principalId);
                        if (entityNamePrincipalName != null) {
                            aRow.setPrincipalId(principalId);
                            aRow.setEmployeeName(
                                    entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY
                                            : entityNamePrincipalName.getDefaultName().getCompositeName());
                        }
                        aRow.setLeaveCode(lb.getEarnCode());
                        aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate()));
                        aRow.setRequestedHours(lb.getLeaveAmount().toString());
                        aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase());
                        aRow.setDescription(lb.getDescription());
                        aRow.setAssignmentTitle(lb.getAssignmentTitle());
                        rowList.add(aRow);
                    }
                }
            }
            // Adding disapproved blocks.
            if (disapprovedBlocks != null && !disapprovedBlocks.isEmpty()) {
                for (LeaveBlockHistory lb : disapprovedBlocks) {
                    String principalId = lb.getPrincipalId();
                    LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow();
                    // Set Employee Name 
                    EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService()
                            .getDefaultNamesForPrincipalId(principalId);
                    if (entityNamePrincipalName != null) {
                        aRow.setPrincipalId(principalId);
                        aRow.setEmployeeName(
                                entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY
                                        : entityNamePrincipalName.getDefaultName().getCompositeName());
                    }
                    aRow.setLeaveCode(lb.getEarnCode());
                    aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate()));
                    aRow.setRequestedHours(lb.getLeaveAmount().toString());
                    aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase());
                    aRow.setDescription(lb.getDescription());
                    aRow.setAssignmentTitle(lb.getAssignmentTitle());
                    rowList.add(aRow);
                }
            }

            leaveReqCalendarDay.setLeaveReqRows(rowList);
            if (!rowList.isEmpty() && rowList.size() > 0) {
                requestList.addAll(rowList);
            }
            dayNumber++;
        }

        leaveReqCalendarDay.setDayNumberString(currentDisplayDateTime.dayOfMonth().getAsShortText());
        leaveReqCalendarDay
                .setDateString(currentDisplayDateTime.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT));

        leaveReqCalendarWeek.getDays().add(leaveReqCalendarDay);

        if (leaveReqCalendarWeek.getDays().size() == DateTimeConstants.DAYS_PER_WEEK) {
            getWeeks().add(leaveReqCalendarWeek);
            leaveReqCalendarWeek = new LeaveRequestCalendarWeek();
        }

        currentDisplayDateTime = currentDisplayDateTime.plusDays(1);
    }

    if (!leaveReqCalendarWeek.getDays().isEmpty()) {
        getWeeks().add(leaveReqCalendarWeek);
    }

}

From source file:org.kuali.kpme.tklm.leave.calendar.validation.LeaveCalendarValidationUtil.java

License:Educational Community License

public static List<String> validateSpanningWeeks(LeaveCalendarWSForm lcf) {
    List<String> errors = new ArrayList<String>();

    boolean spanningWeeks = lcf.getSpanningWeeks().equalsIgnoreCase("y");
    if (!spanningWeeks) {
        EarnCode ec = HrServiceLocator.getEarnCodeService().getEarnCode(lcf.getSelectedEarnCode(),
                TKUtils.formatDateString(lcf.getStartDate()));
        DateTime startDate = null;
        DateTime endDate = null;// w w  w .  j  a  v  a2s . co  m

        if (ec != null && !ec.getRecordMethod().equals(HrConstants.RECORD_METHOD.TIME)) {
            startDate = TKUtils.formatDateString(lcf.getStartDate()).toDateTimeAtStartOfDay();
            endDate = TKUtils.formatDateString(lcf.getEndDate()).toDateTimeAtStartOfDay();
        } else {
            startDate = TKUtils.formatDateTimeString(lcf.getStartDate());
            endDate = TKUtils.formatDateTimeString(lcf.getEndDate());
        }

        boolean isOnlyWeekendSpan = true;
        while ((startDate.isBefore(endDate) || startDate.isEqual(endDate)) && isOnlyWeekendSpan) {
            if (startDate.getDayOfWeek() != DateTimeConstants.SATURDAY
                    && startDate.getDayOfWeek() != DateTimeConstants.SUNDAY) {
                isOnlyWeekendSpan = false;
            }
            startDate = startDate.plusDays(1);
        }
        if (isOnlyWeekendSpan) {
            errors.add("Weekend day is selected, but include weekends checkbox is not checked"); //errorMessages
        }
    }

    return errors;
}