
com.magictools.core.date.DateRange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magic-tools-all Show documentation
Show all versions of magic-tools-all Show documentation
magic-tools 是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
The newest version!
package com.magictools.core.date;
import com.magictools.core.lang.Range;
import java.util.Date;
/**
* 日期范围
*
* @author looly
* @since 4.1.0
*/
public class DateRange extends Range {
private static final long serialVersionUID = 1L;
/**
* 构造,包含开始和结束日期时间
*
* @param start 起始日期时间(包括)
* @param end 结束日期时间(包括)
* @param unit 步进单位
*/
public DateRange(Date start, Date end, DateField unit) {
this(start, end, unit, 1);
}
/**
* 构造,包含开始和结束日期时间
*
* @param start 起始日期时间(包括)
* @param end 结束日期时间(包括)
* @param unit 步进单位
* @param step 步进数
*/
public DateRange(Date start, Date end, DateField unit, int step) {
this(start, end, unit, step, true, true);
}
/**
* 构造
*
* @param start 起始日期时间
* @param end 结束日期时间
* @param unit 步进单位
* @param step 步进数
* @param isIncludeStart 是否包含开始的时间
* @param isIncludeEnd 是否包含结束的时间
*/
public DateRange(Date start, Date end, DateField unit, int step, boolean isIncludeStart, boolean isIncludeEnd) {
super(DateUtil.date(start), DateUtil.date(end), (current, end1, index) -> {
final DateTime dt = DateUtil.date(start).offsetNew(unit, (index + 1) * step);
if (dt.isAfter(end1)) {
return null;
}
return dt;
}, isIncludeStart, isIncludeEnd);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy