Merge branch 'v5-dev' of gitee.com:dromara/hutool into v5-dev

This commit is contained in:
Looly 2022-09-30 19:00:06 +08:00
commit c4133dd981
2 changed files with 28 additions and 0 deletions

View File

@ -2247,6 +2247,26 @@ public class DateUtil extends CalendarUtil {
return startTime.before(realEndTime) && endTime.after(realStartTime);
}
/**
* 是否为本月最后一天
* @param dateTime {@link DateTime}
* @return 是否为本月最后一天
* @since 5.8.8
*/
public static boolean isLastDayOfMonth(DateTime dateTime){
return dateTime.dayOfMonth()==getLastDayOfMonth(dateTime);
}
/**
* 获得本月的最后一天
* @param dateTime {@link DateTime}
* @return
* @since 5.8.8
*/
public static int getLastDayOfMonth(DateTime dateTime){
return Month.getLastDay(dateTime.month(),dateTime.isLeapYear());
}
// ------------------------------------------------------------------------ Private method start
/**

View File

@ -1094,4 +1094,12 @@ public class DateUtilTest {
DateUtil.parse(sourceStr));
Assert.assertTrue(between);
}
@Test
public void isLastDayTest(){
DateTime dateTime = DateUtil.parse("2022-09-30");
int dayOfMonth = DateUtil.getLastDayOfMonth(dateTime);
Assert.assertEquals(dayOfMonth,dateTime.dayOfMonth());
Assert.assertTrue("not is last day of this month !!",DateUtil.isLastDayOfMonth(dateTime));
}
}