[server][xary] - 完成实际Xray配置更新的全流程
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package io.wdd.common.utils;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -24,6 +26,15 @@ public class TimeUtils {
|
||||
|
||||
private static final Map<String, Long> times = new LinkedHashMap<>();
|
||||
|
||||
private static final String FULL_SPLIT_TIME_FORMAT = "yyyy-MM-dd-HH-mm-ss";
|
||||
private static final String COMMON_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
|
||||
/**
|
||||
* 在五秒误差内的一个统一时间
|
||||
*/
|
||||
private static LocalDateTime UNIFORM_TIME;
|
||||
|
||||
static {
|
||||
times.put(
|
||||
"year",
|
||||
@@ -59,7 +70,7 @@ public class TimeUtils {
|
||||
|
||||
byte[] timeBytes = LocalDateTime
|
||||
.now(SYSTEM_TIME_ZONE_ID)
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||
.format(DateTimeFormatter.ofPattern(COMMON_TIME_FORMAT))
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
return ByteBuffer.wrap(timeBytes);
|
||||
@@ -70,12 +81,34 @@ public class TimeUtils {
|
||||
return LocalDateTime.now(SYSTEM_TIME_ZONE_ID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 获取五秒时间误差内的统一时间
|
||||
*/
|
||||
public static String UniformFormatTimeString() {
|
||||
|
||||
if (ObjectUtils.isEmpty(UNIFORM_TIME)) {
|
||||
UNIFORM_TIME = currentTime();
|
||||
return currentFormatTimeString();
|
||||
}
|
||||
|
||||
// 旧的时间和新时间之家误差小于5秒,那么使用同一个时间
|
||||
if (UNIFORM_TIME
|
||||
.plusSeconds(5)
|
||||
.isAfter(currentTime())) {
|
||||
UNIFORM_TIME = currentTime();
|
||||
}
|
||||
|
||||
return localDateTimeFormatString(UNIFORM_TIME);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 格式化 去掉时间中的毫秒数
|
||||
*/
|
||||
public static LocalDateTime currentFormatTime() {
|
||||
|
||||
DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern(COMMON_TIME_FORMAT);
|
||||
|
||||
String format = LocalDateTime
|
||||
.now(SYSTEM_TIME_ZONE_ID)
|
||||
@@ -92,7 +125,7 @@ public class TimeUtils {
|
||||
public static String currentFormatTimeString() {
|
||||
|
||||
return currentFormatTime()
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss"));
|
||||
.format(DateTimeFormatter.ofPattern(FULL_SPLIT_TIME_FORMAT));
|
||||
}
|
||||
|
||||
public static LocalDateTime cvFromDate(Date date) {
|
||||
@@ -113,7 +146,7 @@ public class TimeUtils {
|
||||
|
||||
return LocalDateTime
|
||||
.now(SYSTEM_TIME_ZONE_ID)
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
.format(DateTimeFormatter.ofPattern(COMMON_TIME_FORMAT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,13 +156,29 @@ public class TimeUtils {
|
||||
|
||||
return LocalDateTime
|
||||
.now(SYSTEM_TIME_ZONE_ID)
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss"));
|
||||
.format(DateTimeFormatter.ofPattern(FULL_SPLIT_TIME_FORMAT));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 输出格式为 COMMON_TIME_FORMAT "yyyy-MM-dd HH:mm:ss"
|
||||
*
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
public static String localDateTimeString(LocalDateTime time) {
|
||||
return time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
return time.format(DateTimeFormatter.ofPattern(COMMON_TIME_FORMAT));
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出格式为 FULL_SPLIT_TIME_FORMAT "yyyy-MM-dd-HH-mm-ss"
|
||||
*
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
public static String localDateTimeFormatString(LocalDateTime time) {
|
||||
return time.format(DateTimeFormatter.ofPattern(FULL_SPLIT_TIME_FORMAT));
|
||||
}
|
||||
|
||||
public static String toRelative(long duration, int maxLevel) {
|
||||
|
||||
Reference in New Issue
Block a user