1.修复套餐过期续费计算价格错误的bug

2.优化套餐时间显示,亚马逊服务器时间转换当前时区时间
This commit is contained in:
yezhiqiu
2026-01-21 17:40:14 +08:00
parent 66160b45e0
commit d6d1ad93f2
8 changed files with 87 additions and 61 deletions

View File

@@ -10,6 +10,7 @@ import java.time.Period
import java.util.Calendar
import java.util.Date
import java.util.Locale
import java.util.TimeZone
import java.util.regex.Pattern
import kotlin.math.atan2
import kotlin.math.cos
@@ -50,16 +51,15 @@ class Utils {
/**
* 时间戳转指定格式时间
*
* @param time 13位时间戳
* @param cTimestamp 13位时间戳
* @return 时间
*/
fun formatTime(time: Long, format: String): String {
fun formatTime(cTimestamp: Long, format: String): String {
val timeMillis = if (cTimestamp < 1000000000000) cTimestamp * 1000 else cTimestamp
// 创建一个使用系统默认时区的格式化器
val sdf = SimpleDateFormat(format, Locale.getDefault())
return if (time < 1000000000000) {
sdf.format(Date(time * 1000))
} else {
sdf.format(Date(time))
}
// 直接将时间戳代表UTC时刻格式化为本地时间字符串
return sdf.format(Date(timeMillis))
}
/**
@@ -94,12 +94,16 @@ class Utils {
/**
* 把字符串转成时间戳,返回13位时间戳
* @param parseFormat 字符串是什么格式的日期就传什么格式
* @param isUtc 是否是0时区utc
*/
fun stringToTimestamp(
dateString: String, parseFormat: String = DATE_FORMAT_PATTERN_CN2
dateString: String,
parseFormat: String = DATE_FORMAT_PATTERN_CN2,
isUtc: Boolean = false
): Long {
return try {
val formatter = SimpleDateFormat(parseFormat, Locale.getDefault())
if (isUtc) formatter.timeZone = TimeZone.getTimeZone("UTC")
val date = formatter.parse(dateString)
date?.time ?: 0
} catch (e: Exception) {
@@ -109,6 +113,18 @@ class Utils {
}
}
fun timestampAddHowTimestamp(cTimestamp: Long, period: Int, timeUnit: String): Long {
val timeMillis = if (cTimestamp < 1000000000000) cTimestamp * 1000 else cTimestamp
val calendar = Calendar.getInstance()
calendar.timeInMillis = timeMillis
when (timeUnit) {
"DAY" -> calendar.add(Calendar.DAY_OF_MONTH, period)
"MONTH" -> calendar.add(Calendar.MONTH, period)
"YEAR" -> calendar.add(Calendar.YEAR, period)
}
return calendar.timeInMillis
}
/**
* 获取这个时间戳的,前几天13位时间戳
*/
@@ -134,7 +150,7 @@ class Utils {
val period = Period.between(LocalDate.parse(startDate), LocalDate.parse(endDate))
result[0] = "${period.years}"
result[1] = "${period.months}"
result[2] = "${if(period.days<0) 0 else period.days}"
result[2] = "${if (period.days < 0) 0 else period.days}"
} else {
val dfs = SimpleDateFormat(DATE_FORMAT_PATTERN_CN, Locale.getDefault())
val sDate = dfs.parse(startDate)!!
@@ -162,7 +178,7 @@ class Utils {
}
result[0] = "$years"
result[1] = "$months"
result[2] = "${if(days<0) 0 else days}"
result[2] = "${if (days < 0) 0 else days}"
}
return result
}