mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add method
This commit is contained in:
parent
dc97eb7aca
commit
4fc615d224
@ -20,6 +20,7 @@
|
|||||||
* 【core 】 新增copySafely方法与mkdirsSafely方法(pr#527@Gitee)
|
* 【core 】 新增copySafely方法与mkdirsSafely方法(pr#527@Gitee)
|
||||||
* 【core 】 新增MetroHash(pr#532@Gitee)
|
* 【core 】 新增MetroHash(pr#532@Gitee)
|
||||||
* 【core 】 SpringUtil增加publishEvent重载(pr#2139@Github)
|
* 【core 】 SpringUtil增加publishEvent重载(pr#2139@Github)
|
||||||
|
* 【core 】 DateUtil增加rangeContains、rangeNotContains(pr#537@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复ChineseDate农历获取正月出现数组越界BUG(issue#2112@Github)
|
* 【core 】 修复ChineseDate农历获取正月出现数组越界BUG(issue#2112@Github)
|
||||||
|
@ -1887,6 +1887,8 @@ public class DateUtil extends CalendarUtil {
|
|||||||
* @param start 开始区间
|
* @param start 开始区间
|
||||||
* @param end 结束区间
|
* @param end 结束区间
|
||||||
* @return true 包含
|
* @return true 包含
|
||||||
|
* @author handy
|
||||||
|
* @since 5.7.21
|
||||||
*/
|
*/
|
||||||
public static List<DateTime> rangeContains(DateRange start, DateRange end) {
|
public static List<DateTime> rangeContains(DateRange start, DateRange end) {
|
||||||
List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start);
|
List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start);
|
||||||
@ -1900,6 +1902,8 @@ public class DateUtil extends CalendarUtil {
|
|||||||
* @param start 开始区间
|
* @param start 开始区间
|
||||||
* @param end 结束区间
|
* @param end 结束区间
|
||||||
* @return true 包含
|
* @return true 包含
|
||||||
|
* @author handy
|
||||||
|
* @since 5.7.21
|
||||||
*/
|
*/
|
||||||
public static List<DateTime> rangeNotContains(DateRange start, DateRange end) {
|
public static List<DateTime> rangeNotContains(DateRange start, DateRange end) {
|
||||||
List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start);
|
List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start);
|
||||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.date.DateField;
|
|||||||
import cn.hutool.core.date.DateRange;
|
import cn.hutool.core.date.DateRange;
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -58,8 +59,8 @@ public class RangeTest {
|
|||||||
Assert.assertEquals(sb.toString(), "1#2#3#");
|
Assert.assertEquals(sb.toString(), "1#2#3#");
|
||||||
|
|
||||||
StringBuilder sb2 = new StringBuilder();
|
StringBuilder sb2 = new StringBuilder();
|
||||||
DateUtil.rangeConsume(null, null, DateField.DAY_OF_YEAR, a -> sb.append(DateTime.of(a).dayOfMonth()).append("#"));
|
DateUtil.rangeConsume(null, null, DateField.DAY_OF_YEAR, a -> sb2.append(DateTime.of(a).dayOfMonth()).append("#"));
|
||||||
Assert.assertEquals(sb2.toString(), "");
|
Assert.assertEquals(sb2.toString(), StrUtil.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -149,7 +150,8 @@ public class RangeTest {
|
|||||||
DateRange endRange = DateUtil.range(start1, end1, DateField.DAY_OF_YEAR);
|
DateRange endRange = DateUtil.range(start1, end1, DateField.DAY_OF_YEAR);
|
||||||
// 交集
|
// 交集
|
||||||
List<DateTime> dateTimes = DateUtil.rangeContains(startRange, endRange);
|
List<DateTime> dateTimes = DateUtil.rangeContains(startRange, endRange);
|
||||||
dateTimes.parallelStream().forEach(System.out::println);
|
Assert.assertEquals(1, dateTimes.size());
|
||||||
|
Assert.assertEquals(DateUtil.parse("2017-01-31"), dateTimes.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -164,7 +166,9 @@ public class RangeTest {
|
|||||||
DateRange endRange = DateUtil.range(start1, end1, DateField.DAY_OF_YEAR);
|
DateRange endRange = DateUtil.range(start1, end1, DateField.DAY_OF_YEAR);
|
||||||
// 差集
|
// 差集
|
||||||
List<DateTime> dateTimes1 = DateUtil.rangeNotContains(startRange, endRange);
|
List<DateTime> dateTimes1 = DateUtil.rangeNotContains(startRange, endRange);
|
||||||
dateTimes1.parallelStream().forEach(System.out::println);
|
|
||||||
|
Assert.assertEquals(1, dateTimes1.size());
|
||||||
|
Assert.assertEquals(DateUtil.parse("2017-01-31"), dateTimes1.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user