mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bug
This commit is contained in:
parent
b8c07fd098
commit
9f1920e498
@ -18,6 +18,7 @@
|
|||||||
* 【core 】 MultipartRequestInputStream改为使用long以支持大文件(issue#I428AN@Gitee)
|
* 【core 】 MultipartRequestInputStream改为使用long以支持大文件(issue#I428AN@Gitee)
|
||||||
* 【core 】 RobotUtl增加getDelay、getRobot方法(pr#1725@Github)
|
* 【core 】 RobotUtl增加getDelay、getRobot方法(pr#1725@Github)
|
||||||
* 【json 】 JSON输出支持ignoreNull(issue#1728@Github)
|
* 【json 】 JSON输出支持ignoreNull(issue#1728@Github)
|
||||||
|
* 【core 】 DateUtil和LocalDateTimeUtil增加isWeekend方法(issue#I42N5A@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复RobotUtil双击右键问题(pr#1721@Github)
|
* 【core 】 修复RobotUtil双击右键问题(pr#1721@Github)
|
||||||
@ -28,6 +29,7 @@
|
|||||||
* 【poi 】 修复BeanSheetReader.read中字段对象为空导致的报错(issue#1729@Github)
|
* 【poi 】 修复BeanSheetReader.read中字段对象为空导致的报错(issue#1729@Github)
|
||||||
* 【core 】 修复DateConverter转换java.sql.Date问题(issue#1729@Github)
|
* 【core 】 修复DateConverter转换java.sql.Date问题(issue#1729@Github)
|
||||||
* 【extra 】 修复CompressUtil中部分方法非static的问题(pr#385@Gitee)
|
* 【extra 】 修复CompressUtil中部分方法非static的问题(pr#385@Gitee)
|
||||||
|
* 【core 】 修复ByteUtil转换端序错误问题(pr#384@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -281,6 +281,18 @@ public class DateUtil extends CalendarUtil {
|
|||||||
return DateTime.of(date).dayOfWeekEnum();
|
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>
|
* 获得指定日期的小时数部分<br>
|
||||||
*
|
*
|
||||||
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import cn.hutool.core.util.ReUtil;
|
import cn.hutool.core.util.ReUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.time.DayOfWeek;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@ -486,4 +487,27 @@ public class LocalDateTimeUtil {
|
|||||||
public static long toEpochMilli(TemporalAccessor temporalAccessor) {
|
public static long toEpochMilli(TemporalAccessor temporalAccessor) {
|
||||||
return TemporalAccessorUtil.toEpochMilli(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -915,4 +915,15 @@ public class DateUtilTest {
|
|||||||
"yyyy-MM-dd HH:mm:ss");
|
"yyyy-MM-dd HH:mm:ss");
|
||||||
Assert.assertEquals("2021-07-14 10:05:38", format);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cn.hutool.core.util;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
public class ByteUtilTest {
|
public class ByteUtilTest {
|
||||||
@ -89,4 +90,47 @@ public class ByteUtilTest {
|
|||||||
|
|
||||||
Assert.assertEquals(short2, short1);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user