Example usage for org.joda.time DateTime plusWeeks

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

Introduction

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

Prototype

public DateTime plusWeeks(int weeks) 

Source Link

Document

Returns a copy of this datetime plus the specified number of weeks.

Usage

From source file:com.quinsoft.zeidon.domains.DateTimeDomain.java

License:Open Source License

private Object addWithContext(Task task, AttributeInstance attributeInstance, AttributeDef attributeDef,
        Object currentValue, Object operand, String contextName) {
    assert !StringUtils.isBlank(contextName);

    if (operand instanceof AttributeInstance)
        operand = ((AttributeInstance) operand).getValue();

    if (!(operand instanceof Integer) && !(operand instanceof Long)) {
        throw new ZeidonException(
                "When adding to DateTime with a context, operand must be integer or long value.  "
                        + "Type of operand = %s",
                operand.getClass().getName()).prependAttributeDef(attributeDef);
    }/*from w ww .j a  va2 s.  c  o  m*/

    int value = ((Number) operand).intValue();
    DateTime dt = (DateTime) currentValue;

    switch (contextName.toLowerCase()) {
    case "day":
    case "days":
        return dt.plusDays(value);

    case "hour":
    case "hours":
        return dt.plusHours(value);

    case "minute":
    case "minutes":
        return dt.plusMinutes(value);

    case "milli":
    case "millis":
    case "millisecond":
    case "milliseconds":
        return dt.plus(((Number) operand).longValue());

    case "month":
    case "months":
        return dt.plusMonths(value);

    case "second":
    case "seconds":
        return dt.plusSeconds(value);

    case "week":
    case "weeks":
        return dt.plusWeeks(value);

    case "year":
    case "years":
        return dt.plusYears(value);
    }

    // TODO Auto-generated method stub
    throw new ZeidonException("Unknown context name '%s' for DateTime domain", contextName)
            .prependAttributeDef(attributeDef);
}

From source file:com.salesmanBuddy.dao.JDBCSalesmanBuddyDAO.java

License:Open Source License

private String wrapReportContentWithBeginningEnd(String content, ReportBeginEnd beginning,
        ReportBeginEnd ending, Integer dealershipId, DateTime from, DateTime to) {

    boolean useDefaultEnding = false;
    String timePeriod = "";
    if (to.isAfter(from.plusMonths(1)))
        timePeriod = "Monthly ";
    else if (to.isAfter(from.plusWeeks(1)))
        timePeriod = "Weekly ";
    else if (to.isAfter(from.plusDays(1)))
        timePeriod = "Daily ";

    StringBuilder sb = new StringBuilder();
    Dealerships dealership = this.getDealershipById(dealershipId);
    String fromTo = new StringBuilder().append(this.printTimeDateForReports(from)).append(" to ")
            .append(this.printTimeDateForReports(to)).toString();
    switch (beginning) {
    case AllSalesmen:
        sb.append("All Salesmen ").append(timePeriod).append("summary report for ").append(dealership.getName())
                .append(" from ").append(fromTo).append(".\n\n");
        sb.append(content);/*from   w w w.  j  av  a 2 s . co  m*/
        useDefaultEnding = true;
        break;

    case DealershipSummary:
        sb.append("Dealership-Wide ").append(timePeriod).append("summary report for ")
                .append(dealership.getName()).append(" from ").append(fromTo).append(".\n\n");
        sb.append(content);
        useDefaultEnding = true;
        break;

    case StockNumberSummary:
        sb.append("Stock Number ").append(timePeriod).append("summary report for ").append(dealership.getName())
                .append(" from ").append(fromTo).append(".\n\n");
        sb.append(content);
        useDefaultEnding = true;
        break;

    case TestDriveNow:
        sb.append(content);
        useDefaultEnding = true;
        break;

    case TestDriveSummary:
        sb.append("Test Drive ").append(timePeriod).append("summary report for ").append(dealership.getName())
                .append(" from ").append(fromTo).append(".\n\n");
        sb.append(content);
        useDefaultEnding = true;
        break;

    case Warnings:
        sb.append("Warnings ").append(timePeriod).append("report for ").append(dealership.getName())
                .append(" from ").append(fromTo).append(".\n\n");
        sb.append(content);
        useDefaultEnding = true;
        break;

    default:
        break;

    }

    if (useDefaultEnding)
        sb.append("\n\nThank you for using Salesman Buddy. If you have any questions, contact us at ")
                .append(SUPPORT_EMAIL);

    return sb.toString();
}

From source file:com.sos.scheduler.model.objects.IntervalConstants.java

License:Apache License

public Interval getInterval() {
    DateTime from = new DateTime();
    DateTime to = null;/*from   w ww .  j a va2 s.  c  o  m*/
    switch (this) {
    case CURRENT_DAY:
        from = from.minusMillis(from.getMillisOfDay());
        to = from.plusDays(1);
        break;
    case CURRENT_WEEK:
        from = from.minusMillis(from.getMillisOfDay()).minusDays(from.getDayOfWeek());
        to = from.plusWeeks(1);
        break;
    case REST_OF_DAY:
        to = from.minusMillis(from.getMillisOfDay()).plusDays(1);
        break;
    case NEXT_24H:
        to = from.plusDays(1);
        break;
    case NEXT_WEEK:
        to = from.plusWeeks(1);
        break;
    }
    return new Interval(from, to);
}

From source file:com.sos.scheduler.model.objects.JodaTools.java

License:Apache License

/**
 * \brief calculate a date for a specific weekday based on a given date
 * \detail//from  www  .  java  2s .c o m
 * @param date - the base date
 * @param weekday - the weekday
 * @return
 */
public static DateTime getNextWeekday(DateTime date, int weekday) {
    if (date.getDayOfWeek() > weekday)
        date = date.plusWeeks(1);
    return date.withDayOfWeek(weekday);
}

From source file:com.sos.scheduler.model.objects.JodaTools.java

License:Apache License

/**
 * \brief calculate a date for a specific weekday based on a given date
 * \detail/*from   www  .  j ava  2s. c  o  m*/
 * @param date - the base date
 * @param weekday - the weekday
 * @return
 */
public static DateTime getWeekdayInMonth(DateTime date, int weekday, int which) {

    if (which < 0) {
        DateTime baseDate = getEndOfMonth(date);
        DateTime d = getPreviousWeekday(baseDate, weekday);
        int weeks = (which * -1) - 1;
        return d.minusWeeks(weeks);
    }

    DateTime baseDate = getStartOfMonth(date);
    DateTime d = getNextWeekday(baseDate, weekday);
    return d.plusWeeks(which - 1);

}

From source file:com.sos.scheduler.model.objects.JSObjDay.java

License:Apache License

@Override
public RunTimeElements getRunTimeElements(Interval timeRange) {
    RunTimeElements result = new RunTimeElements(timeRange);
    RunTimeElements work = getNextSingleStarts(timeRange.getStart());
    for (RunTimeElement runtime : work.values()) {
        DateTime date = runtime.getStartDate();
        if (timeRange.contains(date)) {
            while (timeRange.contains(date)) {
                result.add(new RunTimeElement(date, runtime.getWhenHoliday()));
                date = date.plusWeeks(1);
            }/*from  w  w w  .ja  v a2s.co m*/
        }
    }
    //      Collections.sort(result, DateTimeComparator.getInstance());
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjDay.java

License:Apache License

private RunTimeElements getNextSingleStarts(DateTime baseDate) {
    DateTimeFormatter fmtDate = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTimeFormatter fmtDateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    RunTimeElements result = new RunTimeElements(baseDate);
    logger.debug(getDay().size() + " day elements detected.");
    Iterator<String> it = getDay().iterator();
    while (it.hasNext()) {
        String dayString = it.next();
        logger.debug("parsing day string " + dayString);
        List<Integer> days = JodaTools.getJodaWeekdays(dayString);
        for (int i = 0; i < days.size(); i++) {
            DateTime nextWeekDay = JodaTools.getNextWeekday(baseDate, days.get(i));
            logger.debug("calculated date " + fmtDate.print(nextWeekDay));
            List<Period> periods = getPeriod();
            Iterator<Period> itP = periods.iterator();
            logger.debug(periods.size() + " periods found.");
            while (itP.hasNext()) {
                Period p = itP.next();
                JSObjPeriod period = new JSObjPeriod(objFactory);
                period.setObjectFieldsFrom(p);
                DateTime start = period.getDtSingleStartOrNull(nextWeekDay);
                if (start != null) {
                    logger.debug("start from period " + fmtDateTime.print(start));
                    if (start.isBefore(baseDate)) {
                        start = start.plusWeeks(1);
                        logger.debug("start is corrected to " + fmtDateTime.print(start));
                    }//from   ww  w. j a v a 2s  . c  om
                    RunTimeElement e = new RunTimeElement(start, period.getWhenHoliday());
                    result.add(e);
                }
            }
        }
        //         Collections.sort(result, DateTimeComparator.getInstance());
    }
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjHolidaysWeekdaysDay.java

License:Apache License

public List<DateTime> getDtHolidays(Interval timeRange) {
    List<DateTime> result = new ArrayList<DateTime>();
    List<DateTime> work = getNextSingleStarts(timeRange.getStart());
    for (DateTime date : work) {
        if (timeRange.contains(date)) {
            while (timeRange.contains(date)) {
                result.add(date);/*from  w w  w .  ja  va 2 s .c o  m*/
                date = date.plusWeeks(1);
            }
        }
    }
    Collections.sort(result, DateTimeComparator.getInstance());
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjHolidaysWeekdaysDay.java

License:Apache License

private List<DateTime> getNextSingleStarts(DateTime baseDate) {
    DateTimeFormatter fmtDate = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTimeFormatter fmtDateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    List<DateTime> result = new ArrayList<DateTime>();
    logger.debug(getDay().size() + " day elements detected.");
    Iterator<String> it = getDay().iterator();
    while (it.hasNext()) {
        String dayString = it.next();
        logger.debug("parsing day string " + dayString);
        List<Integer> days = JodaTools.getJodaWeekdays(dayString);
        for (int i = 0; i < days.size(); i++) {
            DateTime nextWeekDay = JodaTools.getNextWeekday(baseDate, days.get(i));
            logger.debug("calculated date " + fmtDate.print(nextWeekDay));
            if (nextWeekDay.isBefore(baseDate)) {
                nextWeekDay = nextWeekDay.plusWeeks(1);
                logger.debug("start is corrected to " + fmtDateTime.print(nextWeekDay));
            }//w  w  w .  j  av  a  2s.co  m
            result.add(nextWeekDay);
        }
        Collections.sort(result, DateTimeComparator.getInstance());
    }
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjWeekdaysDay.java

License:Apache License

@Override
public RunTimeElements getRunTimeElements(Interval timeRange) {
    RunTimeElements result = new RunTimeElements(timeRange);
    RunTimeElements work = getNextSingleStarts(timeRange.getStart());
    for (RunTimeElement runtime : work.values()) {
        DateTime date = runtime.getStartDate();
        if (timeRange.contains(date)) {
            while (timeRange.contains(date)) {
                result.add(new RunTimeElement(date, runtime.getWhenHoliday()));
                date = date.plusWeeks(1);
            }//w w  w .j  av  a 2  s  . c o  m
        }
    }
    //         Collections.sort(result, DateTimeComparator.getInstance());
    return result;
}