mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add patch support
This commit is contained in:
@@ -1849,7 +1849,9 @@ public class DateUtil {
|
||||
* @param checkDate 检查时间,可以是当前时间,既
|
||||
* @return 是否过期
|
||||
* @since 5.1.1
|
||||
* @deprecated 使用isIn方法
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isExpired(Date startDate, Date endDate, Date checkDate) {
|
||||
return betweenMs(startDate, checkDate) > betweenMs(startDate, endDate);
|
||||
}
|
||||
|
@@ -294,7 +294,7 @@ public class ReflectUtil {
|
||||
/**
|
||||
* 设置字段值
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param obj 对象,static字段则此处传Class
|
||||
* @param fieldName 字段名
|
||||
* @param value 值,值类型必须与字段类型匹配,不会自动转换对象类型
|
||||
* @throws UtilException 包装IllegalAccessException异常
|
||||
@@ -303,7 +303,7 @@ public class ReflectUtil {
|
||||
Assert.notNull(obj);
|
||||
Assert.notBlank(fieldName);
|
||||
|
||||
final Field field = getField(obj.getClass(), fieldName);
|
||||
final Field field = getField((obj instanceof Class) ? (Class<?>)obj : obj.getClass(), fieldName);
|
||||
Assert.notNull(field, "Field [{}] is not exist in [{}]", fieldName, obj.getClass().getName());
|
||||
setFieldValue(obj, field, value);
|
||||
}
|
||||
@@ -317,9 +317,7 @@ public class ReflectUtil {
|
||||
* @throws UtilException UtilException 包装IllegalAccessException异常
|
||||
*/
|
||||
public static void setFieldValue(Object obj, Field field, Object value) throws UtilException {
|
||||
Assert.notNull(field, "Field in [{}] not exist !", obj.getClass().getName());
|
||||
|
||||
setAccessible(field);
|
||||
Assert.notNull(field, "Field in [{}] not exist !", obj);
|
||||
|
||||
if (null != value) {
|
||||
Class<?> fieldType = field.getType();
|
||||
@@ -332,10 +330,11 @@ public class ReflectUtil {
|
||||
}
|
||||
}
|
||||
|
||||
setAccessible(field);
|
||||
try {
|
||||
field.set(obj, value);
|
||||
field.set(obj instanceof Class ? null : obj, value);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new UtilException(e, "IllegalAccess for {}.{}", obj.getClass(), field.getName());
|
||||
throw new UtilException(e, "IllegalAccess for {}.{}", obj, field.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -82,6 +82,14 @@ public class DateUtilTest {
|
||||
Assert.assertEquals("2017-03-01 23:59:59", endOfDay.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void truncateTest(){
|
||||
String dateStr2 = "2020-02-29 12:59:34";
|
||||
Date date2 = DateUtil.parse(dateStr2);
|
||||
final DateTime dateTime = DateUtil.truncate(date2, DateField.MINUTE);
|
||||
Assert.assertEquals("2020-02-29 12:59:00", dateTime.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beginAndWeedTest() {
|
||||
String dateStr = "2017-03-01 22:33:23";
|
||||
|
Reference in New Issue
Block a user