Java Code Examples for org.apache.commons.lang3.time.DateUtils#addYears()

The following examples show how to use org.apache.commons.lang3.time.DateUtils#addYears() . 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: MigrationTimerBoundryEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMigrationNonTriggeredInterruptingTimerEvent() {
  // given
  Date futureDueDate = DateUtils.addYears(ClockUtil.getCurrentTime(), 1);
  BpmnModelInstance model = createModel(true, sdf.format(futureDueDate));
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(model);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(model);

  ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());

  MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapEqualActivities()
    .build();

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then
  List<Job> list = managementService.createJobQuery().list();
  assertEquals(1, list.size());
  assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("afterTimer").count());
  assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());
}
 
Example 2
Source File: JobLogController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(int jobGroup, int jobId, int type){

	Date clearBeforeTime = null;
	int clearBeforeNum = 0;
	if (type == 1) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -1);	// 清理一个月之前日志数据
	} else if (type == 2) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -3);	// 清理三个月之前日志数据
	} else if (type == 3) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -6);	// 清理六个月之前日志数据
	} else if (type == 4) {
		clearBeforeTime = DateUtils.addYears(new Date(), -1);	// 清理一年之前日志数据
	} else if (type == 5) {
		clearBeforeNum = 1000;		// 清理一千条以前日志数据
	} else if (type == 6) {
		clearBeforeNum = 10000;		// 清理一万条以前日志数据
	} else if (type == 7) {
		clearBeforeNum = 30000;		// 清理三万条以前日志数据
	} else if (type == 8) {
		clearBeforeNum = 100000;	// 清理十万条以前日志数据
	} else if (type == 9) {
		clearBeforeNum = 0;			// 清理所有日志数据
	} else {
		return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid"));
	}

	xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
	return ReturnT.SUCCESS;
}
 
Example 3
Source File: JobLogController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(int jobGroup, int jobId, int type){

	Date clearBeforeTime = null;
	int clearBeforeNum = 0;
	if (type == 1) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -1);	// 清理一个月之前日志数据
	} else if (type == 2) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -3);	// 清理三个月之前日志数据
	} else if (type == 3) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -6);	// 清理六个月之前日志数据
	} else if (type == 4) {
		clearBeforeTime = DateUtils.addYears(new Date(), -1);	// 清理一年之前日志数据
	} else if (type == 5) {
		clearBeforeNum = 1000;		// 清理一千条以前日志数据
	} else if (type == 6) {
		clearBeforeNum = 10000;		// 清理一万条以前日志数据
	} else if (type == 7) {
		clearBeforeNum = 30000;		// 清理三万条以前日志数据
	} else if (type == 8) {
		clearBeforeNum = 100000;	// 清理十万条以前日志数据
	} else if (type == 9) {
		clearBeforeNum = 0;			// 清理所有日志数据
	} else {
		return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid"));
	}

	xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
	return ReturnT.SUCCESS;
}
 
Example 4
Source File: JobLogController.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(Integer jobGroup, Integer jobId, Integer type) {

    Date clearBeforeTime = null;
    Integer clearBeforeNum = 0;
    if (type == 1) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -1);    // 清理一个月之前日志数据
    } else if (type == 2) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -3);    // 清理三个月之前日志数据
    } else if (type == 3) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -6);    // 清理六个月之前日志数据
    } else if (type == 4) {
        clearBeforeTime = DateUtils.addYears(new Date(), -1);    // 清理一年之前日志数据
    } else if (type == 5) {
        clearBeforeNum = 1000;        // 清理一千条以前日志数据
    } else if (type == 6) {
        clearBeforeNum = 10000;        // 清理一万条以前日志数据
    } else if (type == 7) {
        clearBeforeNum = 30000;        // 清理三万条以前日志数据
    } else if (type == 8) {
        clearBeforeNum = 100000;    // 清理十万条以前日志数据
    } else if (type == 9) {
        clearBeforeNum = null;            // 清理所有日志数据
    } else {
        return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid"));
    }

    xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
    return ReturnT.SUCCESS;
}
 
Example 5
Source File: JobLogController.java    From xmfcn-spring-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(Integer jobGroup, Integer jobId, Integer type) {

    Date clearBeforeTime = null;
    int clearBeforeNum = 0;
    if (type == 1) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -1);    // 清理一个月之前日志数据
    } else if (type == 2) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -3);    // 清理三个月之前日志数据
    } else if (type == 3) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -6);    // 清理六个月之前日志数据
    } else if (type == 4) {
        clearBeforeTime = DateUtils.addYears(new Date(), -1);    // 清理一年之前日志数据
    } else if (type == 5) {
        clearBeforeNum = 1000;        // 清理一千条以前日志数据
    } else if (type == 6) {
        clearBeforeNum = 10000;        // 清理一万条以前日志数据
    } else if (type == 7) {
        clearBeforeNum = 30000;        // 清理三万条以前日志数据
    } else if (type == 8) {
        clearBeforeNum = 100000;    // 清理十万条以前日志数据
    } else if (type == 9) {
        clearBeforeNum = 0;            // 清理所有日志数据
    } else {
        return new ReturnT<String>(ResultCodeMessage.FAILURE, I18nUtil.getString("joblog_clean_type_unvalid"));
    }
    xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
    return ReturnT.SUCCESS;
}
 
Example 6
Source File: JobLogController.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(Integer jobGroup, Integer jobId, Integer type) {

    Date clearBeforeTime = null;
    Integer clearBeforeNum = 0;
    if (type == 1) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -1);    // 清理一个月之前日志数据
    } else if (type == 2) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -3);    // 清理三个月之前日志数据
    } else if (type == 3) {
        clearBeforeTime = DateUtils.addMonths(new Date(), -6);    // 清理六个月之前日志数据
    } else if (type == 4) {
        clearBeforeTime = DateUtils.addYears(new Date(), -1);    // 清理一年之前日志数据
    } else if (type == 5) {
        clearBeforeNum = 1000;        // 清理一千条以前日志数据
    } else if (type == 6) {
        clearBeforeNum = 10000;        // 清理一万条以前日志数据
    } else if (type == 7) {
        clearBeforeNum = 30000;        // 清理三万条以前日志数据
    } else if (type == 8) {
        clearBeforeNum = 100000;    // 清理十万条以前日志数据
    } else if (type == 9) {
        clearBeforeNum = null;            // 清理所有日志数据
    } else {
        return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid"));
    }

    xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
    return ReturnT.SUCCESS;
}
 
Example 7
Source File: DataManagerTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testTemporalType() throws Exception {
    Date nextYear = DateUtils.addYears(AppBeans.get(TimeSource.class).currentTimestamp(), 1);
    LoadContext<User> loadContext = LoadContext.create(User.class).setQuery(
            LoadContext.createQuery("select u from sec$User u where u.createTs = :ts")
                    .setParameter("ts", nextYear, TemporalType.DATE));

    List<User> users = dataManager.loadList(loadContext);
    assertTrue(users.isEmpty());
}
 
Example 8
Source File: RecipientForm.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
public Date getYearAgoDate(){
    return DateUtils.addYears(new Date(), -1);
}
 
Example 9
Source File: MigrationTimerBoundryEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testMigrationTwoNonInterruptingTimerEvents() {
  // given
  Date futureDueDate = DateUtils.addYears(ClockUtil.getCurrentTime(), 1);
  BpmnModelInstance model = Bpmn.createExecutableProcess()
      .startEvent("startEvent")
      .userTask("userTask").name("User Task")
      .boundaryEvent("timerPast")
        .cancelActivity(false)
        .timerWithDate(DUE_DATE_IN_THE_PAST)
      .userTask("past")
      .moveToActivity("userTask")
        .boundaryEvent("timerFuture")
        .cancelActivity(false)
        .timerWithDate(sdf.format(futureDueDate))
      .userTask("future")
      .done();
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(model);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(model);

  ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());

  Job job = managementService.createJobQuery().duedateLowerThan(ClockUtil.getCurrentTime()).singleResult();
  assertNotNull(job);
  managementService.executeJob(job.getId());

  MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapEqualActivities()
    .build();

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then
  List<Job> list = managementService.createJobQuery().list();
  assertEquals(1, list.size());
  assertEquals(1, managementService.createJobQuery().duedateHigherThan(ClockUtil.getCurrentTime()).count());
  assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("past").count());
  assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("future").count());
  assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());
}
 
Example 10
Source File: MigrationTimerBoundryEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testMigrationTwoToOneNonInterruptingTimerEvents() {
  // given
  Date futureDueDate = DateUtils.addYears(ClockUtil.getCurrentTime(), 1);
  BpmnModelInstance sourceModel = Bpmn.createExecutableProcess()
      .startEvent("startEvent")
      .userTask("userTask").name("User Task")
      .boundaryEvent("timerPast")
        .cancelActivity(false)
        .timerWithDate(DUE_DATE_IN_THE_PAST)
      .userTask("past")
      .moveToActivity("userTask")
        .boundaryEvent("timerFuture")
        .cancelActivity(false)
        .timerWithDate(sdf.format(futureDueDate))
      .userTask("future")
      .done();
  BpmnModelInstance targetModel = Bpmn.createExecutableProcess()
      .startEvent("startEvent")
      .userTask("userTask").name("User Task")
        .boundaryEvent("timerFuture")
        .cancelActivity(false)
        .timerWithDate(sdf.format(futureDueDate))
      .userTask("future")
      .done();
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceModel);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetModel);

  ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());

  Job job = managementService.createJobQuery().activityId("timerPast").singleResult();
  assertNotNull(job);
  managementService.executeJob(job.getId());

  MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
      .mapEqualActivities()
      .mapActivities("timerPast", "timerFuture")
      .mapActivities("past", "future")
    .build();

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then
  List<Job> list = managementService.createJobQuery().duedateHigherThan(ClockUtil.getCurrentTime()).list();
  assertEquals(1, list.size());
  assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());
  assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("future").count());
}
 
Example 11
Source File: MigrationTimerBoundryEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testMigrationOneToTwoNonInterruptingTimerEvents() {
  // given
  Date futureDueDate = DateUtils.addYears(ClockUtil.getCurrentTime(), 1);
  BpmnModelInstance sourceModel = Bpmn.createExecutableProcess()
      .startEvent("startEvent")
      .userTask("userTask").name("User Task")
        .boundaryEvent("timerFuture")
        .cancelActivity(false)
        .timerWithDate(sdf.format(futureDueDate))
      .userTask("future")
      .done();
  BpmnModelInstance targetModel = Bpmn.createExecutableProcess()
      .startEvent("startEvent")
      .userTask("userTask").name("User Task")
      .boundaryEvent("timerPast")
        .cancelActivity(false)
        .timerWithDate(DUE_DATE_IN_THE_PAST)
      .userTask("past")
      .moveToActivity("userTask")
        .boundaryEvent("timerFuture")
        .cancelActivity(false)
        .timerWithDate(sdf.format(futureDueDate))
      .userTask("future")
      .done();
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceModel);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetModel);

  ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());

  assertNull(managementService.createJobQuery().activityId("timerPast").singleResult());

  MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
      .mapEqualActivities()
    .build();

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then
  testHelper.assertBoundaryTimerJobMigrated("timerFuture", "timerFuture");
  testHelper.assertBoundaryTimerJobCreated("timerPast");
}
 
Example 12
Source File: DateMinusYears.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void subtract_years_from_date_in_java_apachecommons () {
	
	Calendar superBowlXLV = Calendar.getInstance();
	superBowlXLV.set(2011, 1, 6, 0, 0);
	
	Date numberFour = DateUtils.addYears(superBowlXLV.getTime(), -14);
	
	SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");

	logger.info(dateFormatter.format(superBowlXLV.getTime()));
	logger.info(dateFormatter.format(numberFour));

	assertTrue(numberFour.before(superBowlXLV.getTime()));		
}
 
Example 13
Source File: DatePlusYears.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void add_years_to_date_in_java_apachecommons () {

	Calendar superBowlXLV = Calendar.getInstance();
	superBowlXLV.set(2011, 1, 6, 0, 0);
	
	Date fortyNinersSuck = DateUtils.addYears(superBowlXLV.getTime(), 2);
	
	SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");

	logger.info(dateFormatter.format(superBowlXLV.getTime()));
	logger.info(dateFormatter.format(fortyNinersSuck));

	assertTrue(fortyNinersSuck.after(superBowlXLV.getTime()));
}
 
Example 14
Source File: DateUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 指定日期 <code>date</code>,加减年份.
 * 
 * <h3>说明:</h3>
 * <blockquote>
 * <ol>
 * <li>结果会自动跨月,跨年计算.</li>
 * <li>传入的参数 <code>date</code> 不会改变</li>
 * </ol>
 * </blockquote>
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * DateUtil.addYear(2012-06-29 00:33:05,5)   =20<span style="color:red">17</span>-06-29 00:33:05
 * DateUtil.addYear(2012-06-29 00:33:05,-5)  =20<span style="color:red">07</span>-06-29 00:33:05
 * </pre>
 * 
 * </blockquote>
 * 
 * @param date
 *            任意时间
 * @param year
 *            加减年数 ,<span style="color:red">可以是负数</span>,表示前面多少<br>
 * @return 如果 <code>date</code>是null,抛出 {@link java.lang.IllegalArgumentException}<br>
 *         如果 <code>year==0</code>,那么什么都不做,返回 <code>date</code>,参见 {@link GregorianCalendar#add(int, int)}
 * @throws IllegalArgumentException
 *             如果 <code>date</code> 是<code>null</code>
 * @see Calendar#YEAR
 * @see org.apache.commons.lang3.time.DateUtils#addYears(Date, int)
 */
public static Date addYear(Date date,int year){
    return DateUtils.addYears(date, year);
}