Example usage for org.joda.time LocalDate getDayOfWeek

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

Introduction

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

Prototype

public int getDayOfWeek() 

Source Link

Document

Get the day of week field value.

Usage

From source file:com.helger.datetime.holiday.parser.impl.RelativeToWeekdayInMonthParser.java

License:Apache License

@Override
public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) {
    for (final RelativeToWeekdayInMonth aRelativeToWeekdayInMonth : aConfig.getRelativeToWeekdayInMonth()) {
        if (!isValid(aRelativeToWeekdayInMonth, nYear))
            continue;

        final int nExpectedWeekday = XMLUtil.getWeekday(aRelativeToWeekdayInMonth.getWeekday());
        LocalDate aDate = parse(nYear, aRelativeToWeekdayInMonth.getFixedWeekday());
        final int nDirection = (aRelativeToWeekdayInMonth.getWhen() == When.BEFORE ? -1 : 1);
        while (aDate.getDayOfWeek() != nExpectedWeekday) {
            aDate = aDate.plusDays(nDirection);
        }//from  ww w.j  a  v a2 s . co m

        final IHolidayType aType = XMLUtil.getType(aRelativeToWeekdayInMonth.getLocalizedType());
        final String sPropertyKey = aRelativeToWeekdayInMonth.getDescriptionPropertiesKey();
        aHolidayMap.add(aDate, new ResourceBundleHoliday(aType, sPropertyKey));
    }
}

From source file:com.ideaspymes.arthyweb.ventas.web.controllers.ResumenMetasBean.java

public Integer getDaysBetweenIgnoreWeekends(org.joda.time.LocalDate startDate,
        org.joda.time.LocalDate endDate) {
    // If the start date is equal to the closing date, spent 0 days
    if (startDate.equals(endDate)) {
        return 0;
    }//from ww w  .  ja va 2  s. com

    // A number that represents the day for the start date, Monday = 1 , Tuesday = 2 , Wednesday = 3 ...
    int dayOfWeekStartDateNumber = startDate.getDayOfWeek();

    // If the starting date is Saturday or Sunday , pretend to be Monday
    if (dayOfWeekStartDateNumber == 6 || dayOfWeekStartDateNumber == 7) {
        int DaysToAdd = 8 - dayOfWeekStartDateNumber;
        startDate = startDate.plusDays(DaysToAdd);
        dayOfWeekStartDateNumber = Integer.valueOf(startDate.dayOfWeek().getAsString());
    }

    // How many days have passed counting weekends
    int days = Days.daysBetween(startDate, endDate).getDays();

    // How many weeks have passed
    int weeks = days / 7;
    // Excess days left. E.g. one week and three days the excess will be 3
    int excess = days % 7;

    // Excess of days spent for the weekend , then it must be removed two days
    // the final number of days
    if (excess + dayOfWeekStartDateNumber >= 6) {
        // Week count * 5 working days + excess days - the weekend that excess crossed
        return weeks * 5 + excess - 2;
    }
    // Weeks count * 5 working days + excess days
    return weeks * 5 + excess;
}

From source file:com.ideaspymes.arthyweb.ventas.web.controllers.ResumenMetasBean.java

private boolean isWeekend(LocalDate date) {
    int dayOfWeek = date.getDayOfWeek();
    return dayOfWeek > 5;
}

From source file:com.jjlharrison.jollyday.parser.AbstractHolidayParser.java

License:Apache License

/**
 * Determines if the provided date shall be substituted.
 *
 * @param fixed/*w  w  w.  j a va  2 s.c om*/
 *            a {@link org.joda.time.LocalDate} object.
 * @param mc
 *            a {@link com.jjlharrison.config.MovingCondition} object.
 * @return a boolean.
 */
protected boolean shallBeMoved(LocalDate fixed, MovingCondition mc) {
    return fixed.getDayOfWeek() == xmlUtil.getWeekday(mc.getSubstitute());
}

From source file:com.jjlharrison.jollyday.parser.AbstractHolidayParser.java

License:Apache License

/**
 * Moves the date using the FixedMoving information
 *
 * @param mc/*from   ww w  .ja  va  2s. c  om*/
 * @param fixed
 * @return
 */
private LocalDate moveDate(MovingCondition mc, LocalDate fixed) {
    int weekday = xmlUtil.getWeekday(mc.getWeekday());
    int direction = (mc.getWith() == With.NEXT ? 1 : -1);
    while (fixed.getDayOfWeek() != weekday) {
        fixed = fixed.plusDays(direction);
    }
    return fixed;
}

From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayBetweenFixedParser.java

License:Apache License

/**
 * {@inheritDoc}//from  w  ww .  j av  a  2s .co m
 *
 * Parses the provided configuration and creates holidays for the provided
 * year.
 */
public void parse(int year, Set<Holiday> holidays, final Holidays config) {
    for (FixedWeekdayBetweenFixed fwm : config.getFixedWeekdayBetweenFixed()) {
        if (!isValid(fwm, year)) {
            continue;
        }
        LocalDate from = calendarUtil.create(year, fwm.getFrom());
        LocalDate to = calendarUtil.create(year, fwm.getTo());
        LocalDate result = null;
        for (; !from.isAfter(to);) {
            if (from.getDayOfWeek() == xmlUtil.getWeekday(fwm.getWeekday())) {
                result = from;
                break;
            }
            from = from.plusDays(1);
        }
        if (result != null) {
            HolidayType type = xmlUtil.getType(fwm.getLocalizedType());
            holidays.add(new Holiday(result, fwm.getDescriptionPropertiesKey(), type));
        }
    }
}

From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayInMonthParser.java

License:Apache License

private LocalDate moveToNextRequestedWeekdayByDirection(FixedWeekdayInMonth fwm, LocalDate date,
        int direction) {
    int weekDay = xmlUtil.getWeekday(fwm.getWeekday());
    while (date.getDayOfWeek() != weekDay) {
        date = date.plusDays(direction);
    }/* w  ww . ja  va 2  s .  c o  m*/
    return date;
}

From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayRelativeToFixedParser.java

License:Apache License

/**
 * Moves the day to the first/next occurrence of the weekday and direction specified
 * @param f the specification of the weekday and direction of movement
 * @param day the day to move/*from   w w w  .  ja  va2s  .com*/
 * @return the day moved to the weekday and in the direction as specified
 */
private LocalDate moveDateToFirstOccurenceOfWeekday(FixedWeekdayRelativeToFixed f, LocalDate day) {
    LocalDate movingDay = day;
    do {
        movingDay = f.getWhen() == When.AFTER ? movingDay.plusDays(1) : movingDay.minusDays(1);
    } while (movingDay.getDayOfWeek() != xmlUtil.getWeekday(f.getWeekday()));
    return movingDay;
}

From source file:com.jjlharrison.jollyday.parser.impl.RelativeToFixedParser.java

License:Apache License

/** {@inheritDoc} */
public void parse(int year, Set<Holiday> holidays, final Holidays config) {
    for (RelativeToFixed rf : config.getRelativeToFixed()) {
        if (!isValid(rf, year)) {
            continue;
        }/*  w  w  w . j av a  2s  . co  m*/
        LocalDate fixed = calendarUtil.create(year, rf.getDate());
        if (rf.getWeekday() != null) {
            // if weekday is set -> move to weekday
            int day = xmlUtil.getWeekday(rf.getWeekday());
            int direction = (rf.getWhen() == When.BEFORE ? -1 : 1);
            while (fixed.getDayOfWeek() != day) {
                fixed = fixed.plusDays(direction);
            }
        } else if (rf.getDays() != null) {
            // if number of days set -> move number of days
            fixed = fixed.plusDays(rf.getWhen() == When.BEFORE ? -rf.getDays() : rf.getDays());
        }
        HolidayType type = xmlUtil.getType(rf.getLocalizedType());
        holidays.add(new Holiday(fixed, rf.getDescriptionPropertiesKey(), type));
    }
}

From source file:com.jjlharrison.jollyday.parser.impl.RelativeToWeekdayInMonthParser.java

License:Apache License

/** {@inheritDoc} */
@Override//ww w  .  j  a v a  2s. c o m
public void parse(int year, Set<Holiday> holidays, final Holidays config) {
    for (RelativeToWeekdayInMonth rtfw : config.getRelativeToWeekdayInMonth()) {
        if (!isValid(rtfw, year)) {
            continue;
        }
        LocalDate date = parse(year, rtfw.getFixedWeekday());
        int direction = (rtfw.getWhen() == When.BEFORE ? -1 : 1);
        while (date.getDayOfWeek() != xmlUtil.getWeekday(rtfw.getWeekday())) {
            date = date.plusDays(direction);
        }
        HolidayType type = xmlUtil.getType(rtfw.getLocalizedType());
        holidays.add(new Holiday(date, rtfw.getDescriptionPropertiesKey(), type));
    }
}