mirror of
				https://gitee.com/dromara/hutool.git
				synced 2025-11-01 00:46:56 +08:00 
			
		
		
		
	修复DateUtil.rangeContains未重置问题(issue#IB8OFS@gitee)
This commit is contained in:
		| @@ -7,6 +7,7 @@ | |||||||
| ### 🐣新特性 | ### 🐣新特性 | ||||||
| ### 🐞Bug修复 | ### 🐞Bug修复 | ||||||
| * 【crypto 】      修复JWTSignerUtil.createSigner中algorithmId未转换问题(issue#3806@Github) | * 【crypto 】      修复JWTSignerUtil.createSigner中algorithmId未转换问题(issue#3806@Github) | ||||||
|  | * 【core   】      修复DateUtil.rangeContains未重置问题(issue#IB8OFS@gitee) | ||||||
|  |  | ||||||
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ||||||
| # 5.8.34(2024-11-25) | # 5.8.34(2024-11-25) | ||||||
|   | |||||||
| @@ -1975,8 +1975,8 @@ public class DateUtil extends CalendarUtil { | |||||||
| 	 * @since 5.7.21 | 	 * @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.reset()); | ||||||
| 		List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end); | 		List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end.reset()); | ||||||
| 		return startDateTimes.stream().filter(endDateTimes::contains).collect(Collectors.toList()); | 		return startDateTimes.stream().filter(endDateTimes::contains).collect(Collectors.toList()); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -1990,8 +1990,8 @@ public class DateUtil extends CalendarUtil { | |||||||
| 	 * @since 5.7.21 | 	 * @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.reset()); | ||||||
| 		List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end); | 		List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end.reset()); | ||||||
| 		return endDateTimes.stream().filter(item -> !startDateTimes.contains(item)).collect(Collectors.toList()); | 		return endDateTimes.stream().filter(item -> !startDateTimes.contains(item)).collect(Collectors.toList()); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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()); | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 Looly
					Looly