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

The following examples show how to use org.joda.time.DateTime#plusWeeks() . These examples are extracted from open source projects. 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
/**
 * Gets the interval date time.
 *
 * @param curr the curr
 * @param type the type
 * @param interval the interval
 * @return the interval date time
 */
protected static DateTime plusDateTime(DateTime curr, DateType type, int interval) {
    DateTime result = curr;
    if (DateType.YEAR.equals(type)) {
        result = curr.plusYears(interval);
    } else if (DateType.MONTH.equals(type)) {
        result = curr.plusMonths(interval);
    } else if (DateType.WEEK.equals(type)) {
        result = curr.plusWeeks(interval);
    } else if (DateType.DAY.equals(type)) {
        result = curr.plusDays(interval);
    } else if (DateType.HOUR.equals(type)) {
        result = curr.plusHours(interval);
    } else if (DateType.MINUTE.equals(type)) {
        result = curr.plusMinutes(interval);
    } else if (DateType.SECOND.equals(type)) {
        result = curr.plusSeconds(interval);
    }
    return result;
}
 
Example 2
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 Project: nomulus   File: DomainBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClone_doesNotExtendExpirationForPendingTransfer() {
  // Pending transfers shouldn't affect the expiration time
  DateTime now = DateTime.now(UTC);
  DateTime transferExpirationTime = now.plusDays(1);
  DateTime previousExpiration = now.plusWeeks(2);

  DomainTransferData transferData =
      new DomainTransferData.Builder()
          .setPendingTransferExpirationTime(transferExpirationTime)
          .setTransferStatus(TransferStatus.PENDING)
          .setGainingClientId("TheRegistrar")
          .build();
  domain =
      persistResource(
          domain
              .asBuilder()
              .setRegistrationExpirationTime(previousExpiration)
              .setTransferData(transferData)
              .build());

  assertThat(domain.cloneProjectedAtTime(now).getRegistrationExpirationTime())
      .isEqualTo(previousExpiration);
}
 
Example 4
Source Project: nomulus   File: UpdateTldCommandTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccess_tldStateTransitions() throws Exception {
  DateTime sunriseStart = now;
  DateTime quietPeriodStart = sunriseStart.plusMonths(2);
  DateTime gaStart = quietPeriodStart.plusWeeks(1);
  runCommandForced(
      String.format(
          "--tld_state_transitions=%s=PREDELEGATION,%s=START_DATE_SUNRISE,%s=QUIET_PERIOD,"
              + "%s=GENERAL_AVAILABILITY",
          START_OF_TIME, sunriseStart, quietPeriodStart, gaStart),
      "xn--q9jyb4c");

  Registry registry = Registry.get("xn--q9jyb4c");
  assertThat(registry.getTldState(sunriseStart.minusMillis(1))).isEqualTo(PREDELEGATION);
  assertThat(registry.getTldState(sunriseStart)).isEqualTo(START_DATE_SUNRISE);
  assertThat(registry.getTldState(sunriseStart.plusMillis(1))).isEqualTo(START_DATE_SUNRISE);
  assertThat(registry.getTldState(quietPeriodStart.minusMillis(1))).isEqualTo(START_DATE_SUNRISE);
  assertThat(registry.getTldState(quietPeriodStart)).isEqualTo(QUIET_PERIOD);
  assertThat(registry.getTldState(quietPeriodStart.plusMillis(1))).isEqualTo(QUIET_PERIOD);
  assertThat(registry.getTldState(gaStart.minusMillis(1))).isEqualTo(QUIET_PERIOD);
  assertThat(registry.getTldState(gaStart)).isEqualTo(GENERAL_AVAILABILITY);
  assertThat(registry.getTldState(gaStart.plusMillis(1))).isEqualTo(GENERAL_AVAILABILITY);
  assertThat(registry.getTldState(END_OF_TIME)).isEqualTo(GENERAL_AVAILABILITY);
}
 
Example 5
@Override
public void generateWorkOrders() {
	final int startYearForDocumentElement = getImportService().getStartYearForDocumentElement();

	final org.joda.time.format.DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
	DateTime fromDateTime = fmt.parseDateTime(startYearForDocumentElement + "-01-01");

	DateTime loadedWeekDate = fmt.parseDateTime(startYearForDocumentElement + "-01-01");

	final DateTime toDate = new DateTime();
	while (loadedWeekDate.isBefore(toDate)) {
		loadedWeekDate = loadedWeekDate.plusWeeks(1);

		getJmsSender().send(loadDocumentWorkdestination,
				new LoadDocumentWork(fmt.print(fromDateTime), fmt.print(loadedWeekDate)));
		fromDateTime = fromDateTime.plusWeeks(1);
	}
}
 
Example 6
public CurricularYearWeeklyWorkLoadView(final DegreeCurricularPlan degreeCurricularPlan,
        final ExecutionSemester executionSemester, final Set<ExecutionCourse> executionCourses) {
    final ExecutionDegree executionDegree = findExecutionDegree(executionSemester, degreeCurricularPlan);

    if (executionDegree != null) {
        this.interval =
                new Interval(new DateMidnight(getBegginingOfLessonPeriod(executionSemester, executionDegree)),
                        new DateMidnight(getEndOfExamsPeriod(executionSemester, executionDegree)));
        final Period period = interval.toPeriod();
        int extraWeek = period.getDays() > 0 ? 1 : 0;
        numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1;
        intervals = new Interval[numberOfWeeks];
        for (int i = 0; i < numberOfWeeks; i++) {
            final DateTime start = interval.getStart().plusWeeks(i);
            final DateTime end = start.plusWeeks(1);
            intervals[i] = new Interval(start, end);
        }
        this.executionCourses.addAll(executionCourses);
    }
}
 
Example 7
public WeeklyWorkLoadView(final Interval executionPeriodInterval) {
    this.executionPeriodInterval = executionPeriodInterval;
    final Period period = executionPeriodInterval.toPeriod();
    int extraWeek = period.getDays() > 0 ? 1 : 0;
    numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1;
    intervals = new Interval[numberOfWeeks];
    numberResponses = new int[numberOfWeeks];
    contactSum = new int[numberOfWeeks];
    autonomousStudySum = new int[numberOfWeeks];
    otherSum = new int[numberOfWeeks];
    totalSum = new int[numberOfWeeks];
    for (int i = 0; i < numberOfWeeks; i++) {
        final DateTime start = executionPeriodInterval.getStart().plusWeeks(i);
        final DateTime end = start.plusWeeks(1);
        intervals[i] = new Interval(start, end);
    }
}
 
Example 8
Source Project: liteflow   File: TimeExpressionUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 按某个时间单位添加时间
     * @param dateTime
     * @param n
     * @param timeUnit
     * @return
     */
    public static DateTime calculateTime(DateTime dateTime, int n, TimeUnit timeUnit) {

        DateTime addedDateTime = null;
        switch (timeUnit){
//            case SECOND:
//                addedDateTime = dateTime.plusSeconds(n);
//                break;
            case MINUTE:
                addedDateTime = dateTime.plusMinutes(n);
                break;
            case HOUR:
                addedDateTime = dateTime.plusHours(n);
                break;
            case DAY:
                addedDateTime = dateTime.plusDays(n);
                break;
            case WEEK:
                addedDateTime = dateTime.plusWeeks(n);
                break;
            case MONTH:
                addedDateTime = dateTime.plusMonths(n);
                break;
            case YEAR:
                addedDateTime = dateTime.plusYears(n);
                break;
        }

        return addedDateTime;
    }
 
Example 9
Source Project: Almost-Famous   File: DateUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 根据周数,获取开始日期、结束日期
 *
 * @param week 周期  0本周,-1上周,-2上上周,1下周,2下下周
 * @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};
}
 
Example 10
Source Project: sdb-mall   File: DateUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 根据周数,获取开始日期、结束日期
 * @param week  周期  0本周,-1上周,-2上上周,1下周,2下下周
 * @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};
}
 
Example 11
Source Project: boot-actuator   File: DateUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 根据周数,获取开始日期、结束日期
 * @param week  周期  0本周,-1上周,-2上上周,1下周,2下下周
 * @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};
}
 
Example 12
Source Project: nomulus   File: DomainBaseTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testClone_extendsExpirationForNonExpiredTransferredDomain() {
  // If the transfer implicitly succeeded, the expiration time should be extended even if it
  // hadn't already expired
  DateTime now = DateTime.now(UTC);
  DateTime transferExpirationTime = now.minusDays(1);
  DateTime previousExpiration = now.plusWeeks(2);

  DomainTransferData transferData =
      new DomainTransferData.Builder()
          .setPendingTransferExpirationTime(transferExpirationTime)
          .setTransferStatus(TransferStatus.PENDING)
          .setGainingClientId("TheRegistrar")
          .build();
  Period extensionPeriod = transferData.getTransferPeriod();
  DateTime newExpiration = previousExpiration.plusYears(extensionPeriod.getValue());
  domain =
      persistResource(
          domain
              .asBuilder()
              .setRegistrationExpirationTime(previousExpiration)
              .setTransferData(transferData)
              .build());

  assertThat(domain.cloneProjectedAtTime(now).getRegistrationExpirationTime())
      .isEqualTo(newExpiration);
}
 
Example 13
public static int addTimeSteps(int tempRes, int increment, DateTime start) {
    
    DateTime d;
    
    switch(tempRes) {
    case FrameworkUtils.HOUR:
        d = start.plusHours(increment);
        break;
    case FrameworkUtils.DAY:
        d = start.plusDays(increment);
        break;
    case FrameworkUtils.WEEK:
        d = start.plusWeeks(increment);
        break;
    case FrameworkUtils.MONTH:
        d = start.plusMonths(increment);
        break;
    case FrameworkUtils.YEAR:
        d = start.plusYears(increment);
        break;
    default:
        d = start.plusHours(increment);
        break;
    }
    
    return (int) (d.getMillis()/1000);
    
}
 
Example 14
public static DateTime addTime(int tempRes, int increment, DateTime start) {
    
    DateTime d = null;
    
    switch(tempRes) {
    case FrameworkUtils.HOUR:
        d = start.plusHours(increment);
        break;
    case FrameworkUtils.DAY:
        d = start.plusDays(increment);
        break;
    case FrameworkUtils.WEEK:
        d = start.plusWeeks(increment);
        break;
    case FrameworkUtils.MONTH:
        d = start.plusMonths(increment);
        break;
    case FrameworkUtils.YEAR:
        d = start.plusYears(increment);
        break;
    default:
        d = start.plusHours(increment);
        break;
    }
    
    return d;
    
}
 
Example 15
public WeeklyWorkLoadView(final Interval executionPeriodInterval) {
    this.executionPeriodInterval = executionPeriodInterval;
    final Period period = executionPeriodInterval.toPeriod();
    int extraWeek = period.getDays() > 0 ? 1 : 0;
    numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1;
    intervals = new Interval[numberOfWeeks];
    intervalTypes = new IntervalType[numberOfWeeks];
    for (int i = 0; i < numberOfWeeks; i++) {
        final DateTime start = executionPeriodInterval.getStart().plusWeeks(i);
        final DateTime end = start.plusWeeks(1);
        intervals[i] = new Interval(start, end);
    }
}
 
Example 16
public Interval getInterval() {
    final DateTime beginningOfSemester = new DateTime(getAttends().getBegginingOfLessonPeriod());
    final DateTime firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
    final DateTime start = firstMonday.withFieldAdded(DurationFieldType.weeks(), getWeekOffset().intValue());
    final DateTime end = start.plusWeeks(1);
    return new Interval(start, end);
}
 
Example 17
Source Project: onetwo   File: JodatimeUtilsTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testDate(){
	/*LocalDateTime fromDate = new LocalDateTime(new Date());
	String str = fromDate.toString("yyyy-MM-dd HH:mm:ss.SSS");
	System.out.println("str:"+str);
	LocalTime localTime = fromDate.toLocalTime();
	System.out.println("localTime:"+localTime.toString());
	System.out.println("localTime:"+localTime.toString("yyyy-MM-dd HH:mm:ss"));
	System.out.println("toDateTimeToday:"+localTime.toDateTimeToday().toDate().toLocaleString());
	
	fromDate = new LocalDateTime(new Date());
	fromDate = fromDate.year().setCopy(1970).monthOfYear().setCopy(1).dayOfMonth().setCopy(1);
	System.out.println("fromDate:"+fromDate.toString("yyyy-MM-dd HH:mm:ss"));
	
	Calendar cal = Calendar.getInstance();
	cal.setTime(new Date());
	cal.set(1970, 0, 1);
	System.out.println("cal:"+cal.getTime().toLocaleString());*/
	
	DateTime dt = DateTime.now().millisOfDay().withMinimumValue();
	System.out.println(JodatimeUtils.formatDateTime(dt.toDate()));
	dt = dt.millisOfDay().withMaximumValue();
	System.out.println(JodatimeUtils.formatDateTime(dt.toDate()));
	System.out.println(JodatimeUtils.formatDateTime(JodatimeUtils.atEndOfDate(dt.toDate()).toDate()));
	
	DateTime date = JodatimeUtils.parse("2015-03-18");
	System.out.println("date: " + date.getDayOfMonth());
	Assert.assertEquals(18, date.getDayOfMonth());
	
	date = JodatimeUtils.parse("2016-04-13");
	System.out.println("week: " + date.getWeekOfWeekyear());
	Assert.assertEquals(15, date.getWeekOfWeekyear());
	
	DateTime dateTime = DateTime.parse("2016-04-13");
	System.out.println("dateTime:"+dateTime);
	DateTime start = dateTime.dayOfWeek().withMinimumValue();
	DateTime end = start.plusWeeks(1);
	System.out.println("start:"+start);
	System.out.println("end:"+end);
	Assert.assertEquals("2016-04-11", start.toString("yyyy-MM-dd"));
	Assert.assertEquals("2016-04-18", end.toString("yyyy-MM-dd"));


	start = dateTime.dayOfMonth().withMinimumValue();
	end = start.plusMonths(1);
	System.out.println("start:"+start);
	System.out.println("end:"+end);
	Assert.assertEquals("2016-04-01", start.toString("yyyy-MM-dd"));
	Assert.assertEquals("2016-05-01", end.toString("yyyy-MM-dd"));

	start = dateTime.dayOfYear().withMinimumValue();
	end = start.plusYears(1);
	System.out.println("start:"+start);
	System.out.println("end:"+end);
	Assert.assertEquals("2016-01-01", start.toString("yyyy-MM-dd"));
	Assert.assertEquals("2017-01-01", end.toString("yyyy-MM-dd"));
}
 
Example 18
@Test
public void add_weeks_to_date_in_java_with_joda () {

	DateTime xmas = new DateTime(2012, 12, 25, 0, 0, 0, 0);
	DateTime newYearsDay = xmas.plusWeeks(1);

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

	assertTrue(newYearsDay.isAfter(xmas));
}