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

The following examples show how to use org.joda.time.DateTime#plusWeeks() . 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: ExecutionCourse.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 2
Source File: DatetimeUtil.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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 3
Source File: WeeklyWorkLoadDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 4
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 5
Source File: DomainBaseTest.java    From nomulus with 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 6
Source File: UpdateTldCommandTest.java    From nomulus with 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 7
Source File: RiksdagenDocumentListWorkGeneratorImpl.java    From cia with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: DateUtils.java    From Almost-Famous with 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 9
Source File: WeeklyWorkLoad.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 10
Source File: WeeklyWorkLoadDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 11
Source File: FrameworkUtils.java    From data-polygamy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 12
Source File: FrameworkUtils.java    From data-polygamy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 13
Source File: DomainBaseTest.java    From nomulus with 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 14
Source File: DateUtils.java    From boot-actuator with 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 15
Source File: DateUtils.java    From sdb-mall with 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 16
Source File: TimeExpressionUtils.java    From liteflow with 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 17
Source File: JodatimeUtilsTest.java    From onetwo with 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
Source File: DatePlusWeeks.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@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));
}