mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-10 07:38:00 +08:00
add 添加跨月比较是否在同一周
This commit is contained in:
parent
538874562d
commit
7d4d87be82
@ -359,9 +359,7 @@ public class CalendarUtil {
|
|||||||
if (cal1 == null || cal2 == null) {
|
if (cal1 == null || cal2 == null) {
|
||||||
throw new IllegalArgumentException("The date must not be null");
|
throw new IllegalArgumentException("The date must not be null");
|
||||||
}
|
}
|
||||||
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
return isSameDay(cal1, cal2);
|
||||||
cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
|
|
||||||
cal1.get(Calendar.DAY_OF_WEEK) == cal2.get(Calendar.DAY_OF_WEEK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1006,13 +1006,15 @@ public class DateUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void isSameWeektest() {
|
||||||
// 周六与周日比较
|
// 周六与周日比较
|
||||||
final boolean isSameWeek = DateUtil.isSameWeek(DateTime.of("2022-01-01", "yyyy-MM-dd"), DateTime.of("2022-01-02", "yyyy-MM-dd"), true);
|
final boolean isSameWeek = DateUtil.isSameWeek(DateTime.of("2022-01-01", "yyyy-MM-dd"), DateTime.of("2022-01-02", "yyyy-MM-dd"), true);
|
||||||
Assert.assertTrue(isSameWeek);
|
Assert.assertTrue(isSameWeek);
|
||||||
// 周日与周一比较
|
// 周日与周一比较
|
||||||
final boolean isSameWeek1 = DateUtil.isSameWeek(DateTime.of("2022-01-02", "yyyy-MM-dd"), DateTime.of("2022-01-03", "yyyy-MM-dd"), false);
|
final boolean isSameWeek1 = DateUtil.isSameWeek(DateTime.of("2022-01-02", "yyyy-MM-dd"), DateTime.of("2022-01-03", "yyyy-MM-dd"), false);
|
||||||
Assert.assertTrue(isSameWeek1);
|
Assert.assertTrue(isSameWeek1);
|
||||||
|
// 跨月比较
|
||||||
|
final boolean isSameWeek2 = DateUtil.isSameWeek(DateTime.of("2021-12-29", "yyyy-MM-dd"), DateTime.of("2022-01-01", "yyyy-MM-dd"), true);
|
||||||
|
Assert.assertTrue(isSameWeek2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user