This commit is contained in:
Looly 2021-07-28 01:43:52 +08:00
parent b8c07fd098
commit 9f1920e498
5 changed files with 93 additions and 0 deletions

View File

@ -18,6 +18,7 @@
* 【core 】 MultipartRequestInputStream改为使用long以支持大文件issue#I428AN@Gitee
* 【core 】 RobotUtl增加getDelay、getRobot方法pr#1725@Github
* 【json 】 JSON输出支持ignoreNullissue#1728@Github
* 【core 】 DateUtil和LocalDateTimeUtil增加isWeekend方法issue#I42N5A@Gitee
### 🐞Bug修复
* 【core 】 修复RobotUtil双击右键问题pr#1721@Github
@ -28,6 +29,7 @@
* 【poi 】 修复BeanSheetReader.read中字段对象为空导致的报错issue#1729@Github
* 【core 】 修复DateConverter转换java.sql.Date问题issue#1729@Github
* 【extra 】 修复CompressUtil中部分方法非static的问题pr#385@Gitee
* 【core 】 修复ByteUtil转换端序错误问题pr#384@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -281,6 +281,18 @@ public class DateUtil extends CalendarUtil {
return DateTime.of(date).dayOfWeekEnum();
}
/**
* 是否为周末周六或周日
*
* @param date 判定的日期{@link Date}
* @return 是否为周末周六或周日
* @since 5.7.6
*/
public static boolean isWeekend(Date date) {
final Week week = dayOfWeekEnum(date);
return Week.SATURDAY == week || Week.SUNDAY == week;
}
/**
* 获得指定日期的小时数部分<br>
*

View File

@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
@ -486,4 +487,27 @@ public class LocalDateTimeUtil {
public static long toEpochMilli(TemporalAccessor temporalAccessor) {
return TemporalAccessorUtil.toEpochMilli(temporalAccessor);
}
/**
* 是否为周末周六或周日
*
* @param localDateTime 判定的日期{@link LocalDateTime}
* @return 是否为周末周六或周日
* @since 5.7.6
*/
public static boolean isWeekend(LocalDateTime localDateTime){
return isWeekend(localDateTime.toLocalDate());
}
/**
* 是否为周末周六或周日
*
* @param localDate 判定的日期{@link LocalDate}
* @return 是否为周末周六或周日
* @since 5.7.6
*/
public static boolean isWeekend(LocalDate localDate){
final DayOfWeek dayOfWeek = localDate.getDayOfWeek();
return DayOfWeek.SATURDAY == dayOfWeek || DayOfWeek.SUNDAY == dayOfWeek;
}
}

View File

@ -915,4 +915,15 @@ public class DateUtilTest {
"yyyy-MM-dd HH:mm:ss");
Assert.assertEquals("2021-07-14 10:05:38", format);
}
@Test
public void isWeekendTest(){
DateTime parse = DateUtil.parse("2021-07-28");
Assert.assertFalse(DateUtil.isWeekend(parse));
parse = DateUtil.parse("2021-07-25");
Assert.assertTrue(DateUtil.isWeekend(parse));
parse = DateUtil.parse("2021-07-24");
Assert.assertTrue(DateUtil.isWeekend(parse));
}
}

View File

@ -3,6 +3,7 @@ package cn.hutool.core.util;
import org.junit.Assert;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class ByteUtilTest {
@ -89,4 +90,47 @@ public class ByteUtilTest {
Assert.assertEquals(short2, short1);
}
@Test
public void bytesToLongTest(){
long a = RandomUtil.randomLong(0, Long.MAX_VALUE);
ByteBuffer wrap = ByteBuffer.wrap(ByteUtil.longToBytes(a));
wrap.order(ByteOrder.LITTLE_ENDIAN);
long aLong = wrap.getLong();
Assert.assertEquals(a, aLong);
wrap = ByteBuffer.wrap(ByteUtil.longToBytes(a, ByteOrder.BIG_ENDIAN));
wrap.order(ByteOrder.BIG_ENDIAN);
aLong = wrap.getLong();
Assert.assertEquals(a, aLong);
}
@Test
public void bytesToIntTest(){
int a = RandomUtil.randomInt(0, Integer.MAX_VALUE);
ByteBuffer wrap = ByteBuffer.wrap(ByteUtil.intToBytes(a));
wrap.order(ByteOrder.LITTLE_ENDIAN);
int aInt = wrap.getInt();
Assert.assertEquals(a, aInt);
wrap = ByteBuffer.wrap(ByteUtil.intToBytes(a, ByteOrder.BIG_ENDIAN));
wrap.order(ByteOrder.BIG_ENDIAN);
aInt = wrap.getInt();
Assert.assertEquals(a, aInt);
}
@Test
public void bytesToShortTest(){
short a = (short) RandomUtil.randomInt(0, Short.MAX_VALUE);
ByteBuffer wrap = ByteBuffer.wrap(ByteUtil.shortToBytes(a));
wrap.order(ByteOrder.LITTLE_ENDIAN);
short aShort = wrap.getShort();
Assert.assertEquals(a, aShort);
wrap = ByteBuffer.wrap(ByteUtil.shortToBytes(a, ByteOrder.BIG_ENDIAN));
wrap.order(ByteOrder.BIG_ENDIAN);
aShort = wrap.getShort();
Assert.assertEquals(a, aShort);
}
}