Example usage for org.joda.time DateTime plusDays

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

Introduction

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

Prototype

public DateTime plusDays(int days) 

Source Link

Document

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

Usage

From source file:kr.debop4j.timeperiod.timerange.WeekTimeRange.java

License:Apache License

/**
 * Gets days.//from  www.  j a v a2 s .c o  m
 *
 * @return the days
 */
public List<DayRange> getDays() {
    DateTime startDay = getStartDayStart();
    int dayCount = weekCount * TimeSpec.DaysPerWeek;

    List<DayRange> days = Lists.newArrayListWithCapacity(dayCount);
    for (int d = 0; d < dayCount; d++) {
        days.add(new DayRange(startDay.plusDays(d), getTimeCalendar()));
    }
    return days;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Start time of week./*from w w w. j  ava 2  s  .  c o m*/
 *
 * @param year         the year
 * @param weekOfYear   the week of year
 * @param timeCalendar the time calendar
 * @return the date time
 */
public static DateTime startTimeOfWeek(int year, int weekOfYear, ITimeCalendar timeCalendar) {
    DateTime current = startTimeOfYear(year).minusWeeks(1);
    while (current.getYear() < year + 2) {
        if (current.getWeekyear() == year && current.getWeekOfWeekyear() == weekOfYear)
            break;
        current = current.plusDays(1);
    }
    return current;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * ? ?  ??  ?? ./*  www .j a va 2 s  . c o m*/
 *
 * @param moment     ??
 * @param dayOfWeek ? ?
 */
public static DateTime nextDayOfWeek(final DateTime moment, final DayOfWeek dayOfWeek) {
    final int dow = dayOfWeek.getValue();
    DateTime next = moment.plusDays(1);

    while (next.getDayOfWeek() != dow) {
        next = next.plusDays(1);
    }
    return next;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**  ?  ?(days) ??  */
public static TimeRange getRelativeDayPeriod(DateTime start, int days) {
    return getTimeRange(start, start.plusDays(days));
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/** ? ?   . */
public static List<ITimePeriod> foreachHalfyears(ITimePeriod period) {
    assert period != null;
    if (isTraceEnabled)
        log.trace("[{}]?  Halfyear  ...", period);

    List<ITimePeriod> halfyears = Lists.newArrayList();
    if (period.isAnytime())
        return halfyears;

    assertHasPeriod(period);//w  ww. j a v a  2  s. c om

    if (Times.isSameHalfyear(period.getStart(), period.getEnd())) {
        halfyears.add(new TimeRange(period));
        return halfyears;
    }

    DateTime current = Times.endTimeOfHalfyear(period.getStart());
    halfyears.add(new TimeRange(period.getStart(), current));

    int endHashCode = period.getEnd().getYear() * 10 + Times.halfyearOf(period.getEnd()).getValue();
    current = current.plusDays(1);
    ITimeCalendar calendar = TimeCalendar.getDefault();
    while (current.getYear() * 10 + Times.halfyearOf(current).getValue() < endHashCode) {
        halfyears.add(Times.getHalfyearRange(current, calendar));
        current = current.plusMonths(TimeSpec.MonthsPerHalfyear);
    }

    if (current.compareTo(period.getEnd()) < 0) {
        halfyears.add(new TimeRange(Times.startTimeOfHalfyear(current), period.getEnd()));
    }

    return halfyears;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/** ? ?  . */
public static List<ITimePeriod> foreachQuarters(ITimePeriod period) {
    assert period != null;
    if (isTraceEnabled)
        log.trace("[{}]?  Quarter  ...", period);

    List<ITimePeriod> quarters = Lists.newArrayList();
    if (period.isAnytime())
        return quarters;

    assertHasPeriod(period);/*from  w  w  w .j a v a  2 s  .c om*/

    if (Times.isSameQuarter(period.getStart(), period.getEnd())) {
        quarters.add(new TimeRange(period));
        return quarters;
    }

    DateTime current = Times.endTimeOfQuarter(period.getStart());
    quarters.add(new TimeRange(period.getStart(), current));

    int endHashCode = period.getEnd().getYear() * 10 + Times.quarterOf(period.getEnd()).getValue();
    current = current.plusDays(1);
    ITimeCalendar calendar = TimeCalendar.getDefault();

    while (current.getYear() * 10 + Times.quarterOf(current).getValue() < endHashCode) {
        quarters.add(Times.getQuarterRange(current, calendar));
        current = current.plusMonths(TimeSpec.MonthsPerQuarter);
    }

    if (current.compareTo(period.getEnd()) < 0)
        quarters.add(new TimeRange(Times.startTimeOfQuarter(current), period.getEnd()));

    return quarters;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/** ? ? (Month)  . */
public static List<ITimePeriod> foreachMonths(ITimePeriod period) {
    assert period != null;
    if (isTraceEnabled)
        log.trace("[{}]?  (Month)  ...", period);

    List<ITimePeriod> months = Lists.newArrayList();
    if (period.isAnytime())
        return months;

    assertHasPeriod(period);//from  www.  j  av a 2s  .c om

    if (Times.isSameMonth(period.getStart(), period.getEnd())) {
        months.add(new TimeRange(period));
        return months;
    }

    DateTime current = Times.endTimeOfMonth(period.getStart());
    months.add(new TimeRange(period.getStart(), current));

    DateTime monthEnd = Times.startTimeOfMonth(period.getEnd());
    current = current.plusDays(1);
    ITimeCalendar calendar = TimeCalendar.getDefault();

    while (current.compareTo(monthEnd) < 0) {
        months.add(Times.getMonthRange(current, calendar));
        current = current.plusMonths(1);
    }

    current = Times.startTimeOfMonth(current);
    if (current.compareTo(period.getEnd()) < 0)
        months.add(new TimeRange(current, period.getEnd()));

    return months;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**  ? ?(Day) . */
public static List<ITimePeriod> foreachDays(ITimePeriod period) {
    shouldNotBeNull(period, "period");
    if (isTraceEnabled)
        log.trace("[{}]?  ?(Day)  ...", period);

    List<ITimePeriod> days = Lists.newArrayList();
    if (period.isAnytime())
        return days;

    assertHasPeriod(period);//from  ww  w  . jav a  2  s .  c  o m

    if (Times.isSameDay(period.getStart(), period.getEnd())) {
        days.add(new TimeRange(period));
        return days;
    }

    days.add(new TimeRange(period.getStart(), Times.endTimeOfDay(period.getStart())));

    DateTime endDay = period.getEnd().withTimeAtStartOfDay();
    DateTime current = period.getStart().withTimeAtStartOfDay().plusDays(1);
    ITimeCalendar calendar = TimeCalendar.getDefault();

    while (current.compareTo(endDay) < 0) {
        days.add(Times.getDayRange(current, calendar));
        current = current.plusDays(1);
    }
    if (period.getEnd().getMillisOfDay() > 0)
        days.add(new TimeRange(endDay.withTimeAtStartOfDay(), period.getEnd()));

    return days;
}

From source file:li.klass.fhem.adapter.devices.core.generic.detail.actions.devices.fht.HolidayShort.java

License:Open Source License

DateTime holiday1SwitchTimeFor(int hourOfDay, int minute) {

    int newMinute = (int) ((Math.round(minute / 10.0) * 10) % 60);
    if (newMinute == 0) {
        hourOfDay += minute > 30 ? 1 : 0;
    }/*w  w  w .  ja va  2  s .  co m*/
    hourOfDay %= 24;

    DateTime now = dateService.now();
    DateTime switchTime = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), hourOfDay,
            newMinute);

    if (holidayShortIsTomorrow(switchTime, now)) {
        switchTime = switchTime.plusDays(1);
    }
    return switchTime;
}

From source file:li.klass.fhem.domain.WeatherDevice.java

License:Open Source License

private void parseForecast(String keyValue, String nodeContent, String measured) {
    try {//from   w ww  .  ja v  a 2s  .  co  m
        int underscorePosition = keyValue.indexOf("_");
        String name = keyValue.substring(underscorePosition + 1);

        int prefix = Integer.valueOf(keyValue.substring(2, underscorePosition));
        if (((Integer) 1).equals(prefix))
            return;

        if (!forecastMap.containsKey(prefix)) {
            DateTime measuredDate = PARSE_DATE_FORMAT.parseDateTime(measured);
            DateTime forecastDate = measuredDate.plusDays(prefix - 1);
            String forecastTimeString = WeatherDeviceForecast.FORECAST_DATE_FORMAT.print(forecastDate);

            forecastMap.put(prefix, new WeatherDeviceForecast(forecastTimeString));
        }

        WeatherDeviceForecast forecast = forecastMap.get(prefix);

        if (name.equalsIgnoreCase("CONDITION")) {
            forecast.condition = nodeContent;
        } else if (name.equalsIgnoreCase("DAY_OF_WEEK")) {
            forecast.dayOfWeek = nodeContent;
        } else if (name.equalsIgnoreCase("HIGH_C")) {
            forecast.highTemperature = ValueDescriptionUtil.appendTemperature(nodeContent);
        } else if (name.equalsIgnoreCase("LOW_C")) {
            forecast.lowTemperature = ValueDescriptionUtil.appendTemperature(nodeContent);
        } else if (name.equalsIgnoreCase("ICON")) {
            forecast.icon = nodeContent;
        }
    } catch (Exception e) {
        Log.e(WeatherDevice.class.getName(), "cannot parse forecast", e);
    }
}