change name to DateFormatManager

This commit is contained in:
Looly
2024-10-11 09:07:24 +08:00
parent ae1f3635ce
commit 03681f3d40
12 changed files with 116 additions and 69 deletions

View File

@@ -17,7 +17,7 @@
package org.dromara.hutool.json.jwt;
import org.dromara.hutool.core.codec.binary.Base64;
import org.dromara.hutool.core.date.format.GlobalCustomFormat;
import org.dromara.hutool.core.date.format.DateFormatManager;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.json.JSONConfig;
@@ -38,7 +38,7 @@ public class Claims implements Serializable {
private static final long serialVersionUID = 1L;
// 时间使用秒级时间戳表示
private final JSONConfig CONFIG = JSONConfig.of().setDateFormat(GlobalCustomFormat.FORMAT_SECONDS);
private final JSONConfig CONFIG = JSONConfig.of().setDateFormat(DateFormatManager.FORMAT_SECONDS);
private JSONObject claimJSON;

View File

@@ -18,7 +18,7 @@ package org.dromara.hutool.json.serializer.impl;
import org.dromara.hutool.core.convert.impl.DateConverter;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.date.format.GlobalCustomFormat;
import org.dromara.hutool.core.date.format.DateFormatManager;
import org.dromara.hutool.core.reflect.TypeUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.json.JSON;
@@ -61,9 +61,9 @@ public class DateTypeAdapter implements MatcherJSONSerializer<Date>, MatcherJSON
final Object value;
// 默认为时间戳
if(null == format || GlobalCustomFormat.FORMAT_MILLISECONDS.equals(format)){
if(null == format || DateFormatManager.FORMAT_MILLISECONDS.equals(format)){
value = bean.getTime();
} else if(GlobalCustomFormat.FORMAT_SECONDS.equals(format)){
} else if(DateFormatManager.FORMAT_SECONDS.equals(format)){
value = Math.floorDiv(bean.getTime(), 1000L);
} else {
value = DateUtil.format(bean, format);

View File

@@ -18,7 +18,7 @@ package org.dromara.hutool.json.serializer.impl;
import org.dromara.hutool.core.convert.impl.TemporalAccessorConverter;
import org.dromara.hutool.core.date.TimeUtil;
import org.dromara.hutool.core.date.format.GlobalCustomFormat;
import org.dromara.hutool.core.date.format.DateFormatManager;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.math.NumberUtil;
@@ -90,9 +90,9 @@ public class TemporalTypeAdapter implements MatcherJSONSerializer<TemporalAccess
final Object value;
// 默认为时间戳
if (null == format || GlobalCustomFormat.FORMAT_MILLISECONDS.equals(format)) {
if (null == format || DateFormatManager.FORMAT_MILLISECONDS.equals(format)) {
value = TimeUtil.toEpochMilli(bean);
} else if (GlobalCustomFormat.FORMAT_SECONDS.equals(format)) {
} else if (DateFormatManager.FORMAT_SECONDS.equals(format)) {
value = Math.floorDiv(TimeUtil.toEpochMilli(bean), 1000L);
} else {
value = TimeUtil.format(bean, format);

View File

@@ -22,7 +22,7 @@ import org.dromara.hutool.core.annotation.PropIgnore;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.date.DateFormatPool;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.date.format.GlobalCustomFormat;
import org.dromara.hutool.core.date.format.DateFormatManager;
import org.dromara.hutool.core.io.resource.ResourceUtil;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.StrUtil;
@@ -491,7 +491,7 @@ public class JSONObjectTest {
@Test
public void setDateFormatSecondsTest() {
// 自定义格式为只有秒的时间戳一般用于JWT
final JSONConfig jsonConfig = JSONConfig.of().setDateFormat(GlobalCustomFormat.FORMAT_SECONDS);
final JSONConfig jsonConfig = JSONConfig.of().setDateFormat(DateFormatManager.FORMAT_SECONDS);
final Date date = DateUtil.parse("2020-06-05 11:16:11");
final JSONObject json = new JSONObject(jsonConfig);
@@ -507,7 +507,7 @@ public class JSONObjectTest {
@Test
public void setCustomDateFormatTest() {
final JSONConfig jsonConfig = JSONConfig.of();
jsonConfig.setDateFormat(GlobalCustomFormat.FORMAT_SECONDS);
jsonConfig.setDateFormat(DateFormatManager.FORMAT_SECONDS);
final Date date = DateUtil.parse("2020-06-05 11:16:11");
final JSONObject json = new JSONObject(jsonConfig);

View File

@@ -19,7 +19,7 @@ package org.dromara.hutool.json.jwt;
import lombok.Data;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.date.TimeUtil;
import org.dromara.hutool.core.date.format.GlobalCustomFormat;
import org.dromara.hutool.core.date.format.DateFormatManager;
import org.dromara.hutool.json.JSONConfig;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
@@ -41,7 +41,7 @@ public class IssueI6IS5BTest {
final JwtToken jwtToken = new JwtToken();
jwtToken.setIat(iat);
final JSONObject payloadsData = JSONUtil.parseObj(jwtToken, JSONConfig.of().setDateFormat(GlobalCustomFormat.FORMAT_SECONDS));
final JSONObject payloadsData = JSONUtil.parseObj(jwtToken, JSONConfig.of().setDateFormat(DateFormatManager.FORMAT_SECONDS));
final String token = JWTUtil.createToken(payloadsData, "123".getBytes(StandardCharsets.UTF_8));
Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token);
@@ -62,7 +62,7 @@ public class IssueI6IS5BTest {
final JwtToken2 jwtToken = new JwtToken2();
jwtToken.setIat(iat);
final JSONObject payloadsData = JSONUtil.parseObj(jwtToken, JSONConfig.of().setDateFormat(GlobalCustomFormat.FORMAT_SECONDS));
final JSONObject payloadsData = JSONUtil.parseObj(jwtToken, JSONConfig.of().setDateFormat(DateFormatManager.FORMAT_SECONDS));
final String token = JWTUtil.createToken(payloadsData, "123".getBytes(StandardCharsets.UTF_8));
Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token);