修复DateUtil.rangeContains未重置问题(issue#IB8OFS@gitee)

This commit is contained in:
Looly 2024-12-04 00:29:00 +08:00
parent af5cddf80f
commit 843d1d11dc
3 changed files with 30 additions and 4 deletions

View File

@ -7,6 +7,7 @@
### 🐣新特性
### 🐞Bug修复
* 【crypto 】 修复JWTSignerUtil.createSigner中algorithmId未转换问题issue#3806@Github
* 【core 】 修复DateUtil.rangeContains未重置问题issue#IB8OFS@gitee
-------------------------------------------------------------------------------------------------------------
# 5.8.34(2024-11-25)

View File

@ -1975,8 +1975,8 @@ public class DateUtil extends CalendarUtil {
* @since 5.7.21
*/
public static List<DateTime> rangeContains(DateRange start, DateRange end) {
List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start);
List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end);
List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start.reset());
List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end.reset());
return startDateTimes.stream().filter(endDateTimes::contains).collect(Collectors.toList());
}
@ -1990,8 +1990,8 @@ public class DateUtil extends CalendarUtil {
* @since 5.7.21
*/
public static List<DateTime> rangeNotContains(DateRange start, DateRange end) {
List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start);
List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end);
List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start.reset());
List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end.reset());
return endDateTimes.stream().filter(item -> !startDateTimes.contains(item)).collect(Collectors.toList());
}

View File

@ -0,0 +1,25 @@
package cn.hutool.core.date;
import cn.hutool.core.lang.Console;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
public class IssueIB8OFSTest {
@Test
void rangeTest() {
DateRange startRange = DateUtil.range(
DateUtil.parse("2017-01-01"),
DateUtil.parse("2017-01-31"), DateField.DAY_OF_YEAR);
DateRange endRange = DateUtil.range(
DateUtil.parse("2017-01-31"),
DateUtil.parse("2017-02-02"), DateField.DAY_OF_YEAR);
List<DateTime> dateTimes = DateUtil.rangeContains(startRange, endRange);
Assertions.assertEquals(1, dateTimes.size());
List<DateTime> dateNotTimes = DateUtil.rangeNotContains(startRange, endRange);
Assertions.assertEquals(2, dateNotTimes.size());
}
}