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

The following examples show how to use org.apache.commons.lang3.time.DateUtils#addMonths() . 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: TrackedEntityInstanceQueryBuilderFactory.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String getProgramStartDate(ProgramSettings programSettings, String programUid) {
    DownloadPeriod period = null;
    if (programSettings != null) {
        ProgramSetting specificSetting = programSettings.specificSettings().get(programUid);
        ProgramSetting globalSetting = programSettings.globalSettings();

        if (hasEnrollmentDateDownload(specificSetting)) {
            period = specificSetting.enrollmentDateDownload();
        } else if (hasEnrollmentDateDownload(globalSetting)) {
            period = globalSetting.enrollmentDateDownload();
        }
    }

    if (period == null || period == DownloadPeriod.ANY) {
        return null;
    } else {
        Date programStartDate = DateUtils.addMonths(new Date(), -period.getMonths());
        return BaseIdentifiableObject.dateToSpaceDateStr(programStartDate);
    }
}
 
Example 2
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 3
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 4
Source File: WxMaAnalysisServiceImplTest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMonthlyVisitTrend() throws Exception {
  Date now = new Date();
  Date firstDayOfThisMonth = DateUtils.setDays(now, 1);
  Date lastDayOfLastMonth = DateUtils.addDays(firstDayOfThisMonth, -1);
  Date firstDayOfLastMonth = DateUtils.addMonths(firstDayOfThisMonth, -1);

  final WxMaAnalysisService service = wxMaService.getAnalysisService();
  List<WxMaVisitTrend> trends = service.getMonthlyVisitTrend(firstDayOfLastMonth, lastDayOfLastMonth);
  assertEquals(1, trends.size());
  System.out.println(trends);
}
 
Example 5
Source File: WxMaAnalysisServiceImplTest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMonthlyRetainInfo() throws Exception {
  Date now = new Date();
  Date firstDayOfThisMonth = DateUtils.setDays(now, 1);
  Date lastDayOfLastMonth = DateUtils.addDays(firstDayOfThisMonth, -1);
  Date firstDayOfLastMonth = DateUtils.addMonths(firstDayOfThisMonth, -1);

  final WxMaAnalysisService service = wxMaService.getAnalysisService();
  WxMaRetainInfo retainInfo = service.getMonthlyRetainInfo(firstDayOfLastMonth, lastDayOfLastMonth);
  assertNotNull(retainInfo);
  System.out.println(retainInfo);
}
 
Example 6
Source File: DatePicker.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
private void firePrevNextAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_firePrevNextAction
    if(evt.getSource().equals(jButtonPrevious)) {
        selectedDate = DateUtils.addMonths(selectedDate, -1);
        buildCalendar();
    } else if(evt.getSource().equals(jButtonNext)) {
        selectedDate = DateUtils.addMonths(selectedDate, 1);
        buildCalendar();
    }
}
 
Example 7
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 8
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 9
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 10
Source File: DateUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 减一月
 */
public static Date subMonths(@NotNull final Date date, int amount) {
	return DateUtils.addMonths(date, -amount);
}
 
Example 11
Source File: BulkTimeEntriesApprove.java    From sample-timesheets with Apache License 2.0 4 votes vote down vote up
@Subscribe
@Override
public void onInit(InitEvent event) {
    super.onInit(event);

    timeEntriesTable.getColumn("overtime").setAggregation(
            ScreensHelper.createAggregationInfo(
                    projectsService.getEntityMetaPropertyPath(TimeEntry.class, "overtime"),
                    new TimeEntryOvertimeAggregation()));

    Date previousMonth = DateUtils.addMonths(timeSource.currentTimestamp(), -1);
    dateFrom.setValue(DateUtils.truncate(previousMonth, Calendar.MONTH));
    dateTo.setValue(DateUtils.addDays(DateUtils.truncate(timeSource.currentTimestamp(), Calendar.MONTH), -1));

    approve.addAction(new BaseAction("approveSelected")
            .withHandler(ae -> {
                setStatus(timeEntriesTable.getSelected(), TimeEntryStatus.APPROVED);
            })
            .withCaption(messageBundle.getMessage("approveSelected")));

    approve.addAction(new BaseAction("approveAll")
            .withHandler(ae -> {
                setStatus(timeEntriesDc.getMutableItems(), TimeEntryStatus.APPROVED);
            })
            .withCaption(messageBundle.getMessage("approveAll")));

    reject.addAction(new BaseAction("rejectSelected")
            .withHandler(ae -> {
                setStatus(timeEntriesTable.getSelected(), TimeEntryStatus.REJECTED);
            })
            .withCaption(messageBundle.getMessage("rejectSelected")));

    reject.addAction(new BaseAction("rejectAll")
            .withHandler(ae -> {
                setStatus(timeEntriesDc.getMutableItems(), TimeEntryStatus.REJECTED);
            })
            .withCaption(messageBundle.getMessage("rejectAll")));

    status.setOptionsList(Arrays.asList(TimeEntryStatus.values()));
    user.setOptionsList(projectsService.getManagedUsers(userSession.getCurrentOrSubstitutedUser(), View.MINIMAL));
}
 
Example 12
Source File: CalendarScreen.java    From sample-timesheets with Apache License 2.0 4 votes vote down vote up
public void showPreviousMonth() {
    firstDayOfMonth = DateUtils.addMonths(firstDayOfMonth, -1);
    updateCalendarRange();
}
 
Example 13
Source File: CalendarScreen.java    From sample-timesheets with Apache License 2.0 4 votes vote down vote up
public void showNextMonth() {
    firstDayOfMonth = DateUtils.addMonths(firstDayOfMonth, 1);
    updateCalendarRange();
}
 
Example 14
Source File: DateUtil.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
/**
 * 减一月
 */
public static Date subMonths(@NotNull final Date date, int amount) {
	return DateUtils.addMonths(date, -amount);
}
 
Example 15
Source File: DateUtil.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
/**
 * 加一月
 */
public static Date addMonths(@NotNull final Date date, int amount) {
	return DateUtils.addMonths(date, amount);
}
 
Example 16
Source File: DateUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 加一月
 */
public static Date addMonths(@NotNull final Date date, int amount) {
	return DateUtils.addMonths(date, amount);
}
 
Example 17
Source File: DateUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 减一月
 */
public static Date subMonths(@NotNull final Date date, int amount) {
	return DateUtils.addMonths(date, -amount);
}
 
Example 18
Source File: DateMinusMonths.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void subtract_months_from_date_in_java_apachecommons () {

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

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

	assertTrue(championshipWeekend.before(superBowlXLV.getTime()));
}
 
Example 19
Source File: DatePlusMonths.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void add_months_to_date_in_java_apachecommons () {
	
	Calendar superBowlXLV = Calendar.getInstance();
	superBowlXLV.set(2011, 1, 6, 0, 0);
	
	Date sippinFruityDrinksInMexico = DateUtils.addMonths(superBowlXLV.getTime(), 1);
	
	SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");

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

	assertTrue(sippinFruityDrinksInMexico.after(superBowlXLV.getTime()));		
}
 
Example 20
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.addMonth(2012-10-16 23:12:43,5)  =2013-03-16 23:12:43.932
 * DateUtil.addMonth(2012-10-16 23:12:43,-5) =2012-05-16 23:12:43.943
 * </pre>
 * 
 * </blockquote>
 * 
 * @param date
 *            任意时间
 * @param month
 *            加减月份, <span style="color:red">可以是负数</span>,表示前面多少<br>
 *            比如-3 表示 3个月之前
 * @return 如果 <code>date</code>是null,抛出 {@link java.lang.IllegalArgumentException}<br>
 *         如果 <code>month==0</code>,那么什么都不做,返回 <code>date</code>,参见 {@link GregorianCalendar#add(int, int)}
 * @throws IllegalArgumentException
 *             如果 <code>date</code> 是<code>null</code>
 * @see Calendar#MONTH
 * @see org.apache.commons.lang3.time.DateUtils#addMonths(Date, int)
 */
public static Date addMonth(Date date,int month){
    return DateUtils.addMonths(date, month);
}