Example usage for org.joda.time LocalDate dayOfWeek

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

Introduction

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

Prototype

public Property dayOfWeek() 

Source Link

Document

Get the day of week property which provides access to advanced functionality.

Usage

From source file:com.google.api.ads.adwords.awalerting.util.DateRange.java

License:Open Source License

/**
 * Parse DateRange in ReportDefinitionDateRangeType enum format.
 *///w w  w  . j a v a2  s  .  com
private static DateRange parseEnumFormat(String dateRange) {
    ReportDefinitionDateRangeType dateRangeType;
    try {
        dateRangeType = ReportDefinitionDateRangeType.valueOf(dateRange);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Unknown DateRange type: " + dateRange);
    }

    LocalDate today = LocalDate.now();
    LocalDate startDate;
    LocalDate endDate;
    switch (dateRangeType) {
    case TODAY:
        startDate = endDate = today;
        break;
    case YESTERDAY:
        startDate = endDate = today.minusDays(1);
        break;
    case LAST_7_DAYS:
        startDate = today.minusDays(7);
        endDate = today.minusDays(1);
        break;
    case LAST_WEEK:
        LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek();
        startDate = lastWeekProp.withMinimumValue();
        endDate = lastWeekProp.withMaximumValue();
        break;
    case THIS_MONTH:
        LocalDate.Property thisMonthProp = today.dayOfMonth();
        startDate = thisMonthProp.withMinimumValue();
        endDate = thisMonthProp.withMaximumValue();
        break;
    case LAST_MONTH:
        LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth();
        startDate = lastMonthProp.withMinimumValue();
        endDate = lastMonthProp.withMaximumValue();
        break;
    case LAST_14_DAYS:
        startDate = today.minusDays(14);
        endDate = today.minusDays(1);
        break;
    case LAST_30_DAYS:
        startDate = today.minusDays(30);
        endDate = today.minusDays(1);
        break;
    case THIS_WEEK_SUN_TODAY:
        // Joda-Time uses the ISO standard Monday to Sunday week.
        startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue();
        endDate = today;
        break;
    case THIS_WEEK_MON_TODAY:
        startDate = today.dayOfWeek().withMinimumValue();
        endDate = today;
        break;
    case LAST_WEEK_SUN_SAT:
        startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue();
        endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1);
        break;
    // Don't support the following enums
    case LAST_BUSINESS_WEEK:
    case ALL_TIME:
    case CUSTOM_DATE:
    default:
        throw new IllegalArgumentException("Unsupported DateRange type: " + dateRange);
    }

    return new DateRange(startDate, endDate);
}

From source file:com.google.api.ads.adwords.awreporting.model.entities.DateRangeAndType.java

License:Open Source License

/**
 * Parse DateRange in ReportDefinitionDateRangeType enum format.
 */// w  w w. j  a v a2 s.c  o  m
private static DateRangeAndType parseEnumFormat(ReportDefinitionDateRangeType type) {
    LocalDate today = LocalDate.now();
    LocalDate startDate;
    LocalDate endDate;
    switch (type) {
    case TODAY:
        startDate = endDate = today;
        break;
    case YESTERDAY:
        startDate = endDate = today.minusDays(1);
        break;
    case LAST_7_DAYS:
        startDate = today.minusDays(7);
        endDate = today.minusDays(1);
        break;
    case LAST_WEEK:
        LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek();
        startDate = lastWeekProp.withMinimumValue();
        endDate = lastWeekProp.withMaximumValue();
        break;
    case THIS_MONTH:
        LocalDate.Property thisMonthProp = today.dayOfMonth();
        startDate = thisMonthProp.withMinimumValue();
        endDate = thisMonthProp.withMaximumValue();
        break;
    case LAST_MONTH:
        LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth();
        startDate = lastMonthProp.withMinimumValue();
        endDate = lastMonthProp.withMaximumValue();
        break;
    case LAST_14_DAYS:
        startDate = today.minusDays(14);
        endDate = today.minusDays(1);
        break;
    case LAST_30_DAYS:
        startDate = today.minusDays(30);
        endDate = today.minusDays(1);
        break;
    case THIS_WEEK_SUN_TODAY:
        // Joda-Time uses the ISO standard Monday to Sunday week.
        startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue();
        endDate = today;
        break;
    case THIS_WEEK_MON_TODAY:
        startDate = today.dayOfWeek().withMinimumValue();
        endDate = today;
        break;
    case LAST_WEEK_SUN_SAT:
        startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue();
        endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1);
        break;
    // Don't support the following enums
    case LAST_BUSINESS_WEEK:
    case ALL_TIME:
    case CUSTOM_DATE:
    default:
        throw new IllegalArgumentException("Unsupported DateRange type: " + type.value());
    }

    return new DateRangeAndType(startDate, endDate, type);
}

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   w ww.j  a v  a 2 s .  c  o  m*/

    // 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.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

/**
 * Get the day of week from the encodedDate,
  * 1-7./*from   www.j a  v  a 2 s  .c  om*/
 *
 * @param encodedDate   the encoded date
 * @return             week day name.
 */
static int getWeekDay(int encodedDate) {
    LocalDate date = new LocalDate(getYear(encodedDate), getMonth(encodedDate), getDay(encodedDate));
    return date.dayOfWeek().get();
}

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

/**
 * Get the week day name from the encodedDate,
  * 'Monday' ,'Tuesday', etc./*from  w  ww.j av a  2  s .co  m*/
 *
 * @param encodedDate   the encoded date
 * @return             week day name.
 */
static String getWeekDayName(int encodedDate) {
    LocalDate date = new LocalDate(getYear(encodedDate), getMonth(encodedDate), getDay(encodedDate));
    return date.dayOfWeek().getAsText();
}

From source file:courtscheduler.persistence.CourtScheduleIO.java

License:Apache License

private void printMatch(XSSFRow dataRow, Match match, CourtScheduleInfo info) {
    int cellNumber = 0;
    // TEAM/*from w  w  w.jav  a  2 s.co  m*/
    String teamName1 = match.getTeam1().getTeamName();
    dataRow.createCell(cellNumber++).setCellValue(teamName1);

    // VS
    String vs = "vs.";
    dataRow.createCell(cellNumber++).setCellValue(vs);

    // OPPONENT
    String teamName2 = match.getTeam2().getTeamName();
    dataRow.createCell(cellNumber++).setCellValue(teamName2);

    // CONFERENCE
    String conference = match.getConference();

    dataRow.createCell(cellNumber++).setCellValue(conference);

    // DAY
    Integer matchDateIndex = match.getMatchSlot().getDay();
    LocalDate matchDate = info.getConferenceStartDate().plusDays(matchDateIndex);
    String day = matchDate.dayOfWeek().getAsText();
    dataRow.createCell(cellNumber++).setCellValue(day);

    // DATE
    String date = matchDate.toString();
    if (Main.LOG_LEVEL > 1) {
        date = date + " [" + matchDateIndex + "]";
    }
    dataRow.createCell(cellNumber++).setCellValue(date);

    // TIME
    Integer matchTime = match.getMatchSlot().getTime();
    String time = info.getHumanReadableTime(matchTime);
    if (Main.LOG_LEVEL > 1) {
        time = time + " [" + matchTime + "]";
    }
    dataRow.createCell(cellNumber++).setCellValue(time);

    // COURT
    Integer courtId = match.getMatchSlot().getCourt();
    // normal people like their courts indexed from one, not zero,
    // so add one if we're printing for the client
    dataRow.createCell(cellNumber++).setCellValue(courtId + (Main.LOG_LEVEL > 1 ? 0 : 1));

    if (!match.getCanPlayInCurrentSlot()) {
        dataRow.createCell(cellNumber).setCellValue("WARNING: Team is scheduled when they cannot play");
    } else if (match.wasPostProcessed()) {
        dataRow.createCell(cellNumber)
                .setCellValue("VERIFY: Check that this match meets DH/B2B/NST constraints");
    }
}

From source file:eafit.cdei.asignacion.vo.Teacher.java

public void addCourseAvaliability(List<TimeDayLocation> pt) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("YY-MM-DDH:mm:ss");
    LocalDate mondayDate = LocalDate.parse("2014-10-20");

    meetTimeIntervals = new ArrayList<>();

    for (TimeDayLocation tdl : pt) {
        String key = tdl.getDow().dayOfWeek().getAsText() + tdl.getTimeStartString() + tdl.getTimeEndString();
        if (!mapCoursesAvaliability.containsKey(key)) {
            getMapCoursesAvaliability().put(key, tdl);
            getListAvaliability().add(tdl);

            for (int x = 0; x <= 6; x++) {
                LocalDate tmpStartDate = mondayDate.plusDays(x);
                String tmpDay = tmpStartDate.toString("EEEE");
                if (tmpStartDate.dayOfWeek().equals(tdl.getDow().dayOfWeek())) {
                    DateTime tmpStartDateTime = DateTime.parse(
                            tmpStartDate.toString("YY-MM-DD") + tdl.getTimeStart().toString("H:mm:ss"), fmt);
                    DateTime tmpStopDateTime = DateTime.parse(
                            tmpStartDate.toString("YY-MM-DD") + tdl.getTimeEnd().toString("H:mm:ss"), fmt);
                    meetTimeIntervals.add(new Interval(tmpStartDateTime, tmpStopDateTime));
                }/* w w  w .j a  v  a2  s  .  c  o m*/
            }
        }
    }
}

From source file:io.renren.common.utils.DateUtils.java

License:Apache License

/**
 * ????//from   w ww  .  ja v  a2s .  c  o  m
 * @param week    0-1-212
 * @return  date[0]?date[1]?
 */
public static Date[] getWeekStartAndEnd(int week) {
    DateTime dateTime = new DateTime();
    LocalDate date = new LocalDate(dateTime.plusWeeks(week));

    date = date.dayOfWeek().withMinimumValue();
    Date beginDate = date.toDate();
    Date endDate = date.plusDays(6).toDate();
    return new Date[] { beginDate, endDate };
}

From source file:liteshiftwindow.LSForm.java

public LocalDate getSunday(LocalDate selectedDate) {

    // If the user selected a Sunday, return that sunday.
    if (selectedDate.dayOfWeek().get() == 7) {
        return selectedDate;
    } else {/*  w w w. ja  v a 2s.  c o m*/
        selectedDate = selectedDate.minusWeeks(1);
        return selectedDate.withDayOfWeek(7);
    }
}

From source file:nl.surfnet.coin.selfservice.control.StatisticsController.java

License:Apache License

private LocalDate getEndDate(String intervalType, LocalDate startDate) {
    LocalDate endDate;/*from w ww  .  j a  v  a2  s  .  c o  m*/
    switch (intervalType) {
    case "week":
        endDate = startDate.dayOfWeek().withMaximumValue();
        break;
    case "month":
        endDate = startDate.dayOfMonth().withMaximumValue();
        break;
    case "year":
        endDate = startDate.dayOfYear().withMaximumValue();
        break;
    default:
        throw new IllegalArgumentException(intervalType);
    }
    return endDate;
}