Java Code Examples for org.joda.time.DateTime#minusWeeks()

The following examples show how to use org.joda.time.DateTime#minusWeeks() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShoppingListServiceImpl.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
private DateTime calculateReminderTime(DateTime date, int inputAmount, int inputChoice)
{
    DateTime dateTime = new DateTime();

    switch ( inputChoice )
    {
        case 0:
            dateTime = date.minusMinutes(inputAmount);
            break;
        case 1:
            dateTime = date.minusHours(inputAmount);
            break;
        case 2:
            dateTime = date.minusDays(inputAmount);
            break;
        case 3:
            dateTime = date.minusWeeks(inputAmount);
    }

    return dateTime;
}
 
Example 2
Source File: ChronologyBasedCalendar.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private DateInterval toWeekIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length )
{
    DateTime from = dateTimeUnit.toJodaDateTime( chronology );

    if ( offset > 0 )
    {
        from = from.plusWeeks( offset );
    }
    else if ( offset < 0 )
    {
        from = from.minusWeeks( -offset );
    }

    DateTime to = new DateTime( from ).plusWeeks( length ).minusDays( 1 );

    DateTimeUnit fromDateTimeUnit = DateTimeUnit.fromJodaDateTime( from );
    DateTimeUnit toDateTimeUnit = DateTimeUnit.fromJodaDateTime( to );

    fromDateTimeUnit.setDayOfWeek( isoWeekday( fromDateTimeUnit ) );
    toDateTimeUnit.setDayOfWeek( isoWeekday( toDateTimeUnit ) );

    return new DateInterval( toIso( fromDateTimeUnit ), toIso( toDateTimeUnit ), DateIntervalType.ISO8601_WEEK );
}
 
Example 3
Source File: HoltWintersDetector.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private DateTime getTrainingStartTime(DateTime windowStart) {
  DateTime trainStart;
  if (isMultiDayGranularity()) {
    trainStart = windowStart.minusDays(timeGranularity.getSize() * LOOKBACK);
  } else if (this.monitoringGranularity.endsWith(TimeGranularity.MONTHS)) {
    trainStart = windowStart.minusMonths(LOOKBACK);
  } else if (this.monitoringGranularity.endsWith(TimeGranularity.WEEKS)) {
    trainStart = windowStart.minusWeeks(LOOKBACK);
  } else {
    trainStart = windowStart.minusDays(LOOKBACK);
  }
  return trainStart;
}
 
Example 4
Source File: ParameterSet.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
private String createDefaultTimespan() {
    DateTime now = new DateTime();
    DateTime lastWeek = now.minusWeeks(1);
    return new Interval(lastWeek, now).toString();
}
 
Example 5
Source File: DropScheduleService.java    From mojito with Apache License 2.0 3 votes vote down vote up
DateTime getDropCreatedDate(DateTime dropDueDate) {

        DateTime dropCreatedDate = dropDueDate.withTime(dropScheduleConfig.getCreatedLocalTime());

        Integer dropDueDateDay = dropDueDate.getDayOfWeek();
        Integer dropStartDateDay = getDueDayToStartDay().get(dropDueDateDay);

        dropCreatedDate = dropCreatedDate.withDayOfWeek(dropStartDateDay);

        if (dropStartDateDay > dropDueDateDay) {
            dropCreatedDate = dropCreatedDate.minusWeeks(1);
        }

        return dropCreatedDate;
    }
 
Example 6
Source File: DateMinusWeeks.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void subtract_weeks_from_date_in_java_with_joda () {
	
	DateTime newYearsDay = new DateTime(2013, 1, 1, 0, 0, 0, 0);
	DateTime xmas = newYearsDay.minusWeeks(1);

	DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss z");
	
	logger.info(newYearsDay.toString(fmt));
	logger.info(xmas.toString(fmt));

	assertTrue(xmas.isBefore(newYearsDay));
}