add method

This commit is contained in:
Looly 2020-08-01 22:52:33 +08:00
parent 232c292dfc
commit 01ac41f08e
3 changed files with 27 additions and 2 deletions

View File

@ -8,6 +8,7 @@
### 新特性
* 【socket】 对NioServer和NioClient改造pr#992@Github
* 【core 】 StrUtil增加filter方法pr#149@Gitee
* 【core 】 DateUtil增加beginOfWeek重载
### Bug修复#

View File

@ -1041,6 +1041,18 @@ public class DateUtil extends CalendarUtil {
return new DateTime(beginOfWeek(calendar(date)));
}
/**
* 获取某周的开始时间
*
* @param date 日期
* @param isMondayAsFirstDay 是否周一做为一周的第一天false表示周日做为第一天
* @return {@link DateTime}
* @since 5.4.0
*/
public static DateTime beginOfWeek(Date date, boolean isMondayAsFirstDay) {
return new DateTime(beginOfWeek(calendar(date), isMondayAsFirstDay));
}
/**
* 获取某周的结束时间周日定为一周的结束
*
@ -1051,6 +1063,18 @@ public class DateUtil extends CalendarUtil {
return new DateTime(endOfWeek(calendar(date)));
}
/**
* 获取某周的结束时间
*
* @param date 日期
* @param isSundayAsLastDay 是否周日做为一周的最后一天false表示周六做为最后一天
* @return {@link DateTime}
* @since 5.4.0
*/
public static DateTime endOfWeek(Date date, boolean isSundayAsLastDay) {
return new DateTime(endOfWeek(calendar(date), isSundayAsLastDay));
}
/**
* 获取某月的开始时间
*

View File

@ -99,7 +99,7 @@ public class DateUtilTest {
}
@Test
public void beginAndWeedTest() {
public void beginOfWeekTest() {
String dateStr = "2017-03-01 22:33:23";
DateTime date = DateUtil.parse(dateStr);
Objects.requireNonNull(date).setFirstDayOfWeek(Week.MONDAY);
@ -121,7 +121,7 @@ public class DateUtilTest {
}
@Test
public void beginAndWeedTest2() {
public void beginOfWeekTest2() {
String beginStr = "2020-03-11";
DateTime date = DateUtil.parseDate(beginStr);
Calendar calendar = date.toCalendar();