1.套餐到期年月日时间重新计算,去掉显示一位数补齐0
This commit is contained in:
@@ -120,7 +120,7 @@ class MySubscriptionAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
val times = Utils.getDayToYearMonthDay(item.surplusDays)
|
||||
val times = Utils.differYear(System.currentTimeMillis(), item.endTime)
|
||||
holder.setText(R.id.tv_add_success_device_expires_days, times[0])
|
||||
holder.setText(R.id.tv_add_success_device_expires_hours, times[1])
|
||||
holder.setText(R.id.tv_add_success_device_expires_min, times[2])
|
||||
|
||||
@@ -78,7 +78,9 @@ class PaymentSuccessActivity :
|
||||
tvPaymentSuccessExpiresOnDate.text = Utils.stringToDate(
|
||||
it.expirationTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN7
|
||||
)
|
||||
val times = Utils.getDayToYearMonthDay(it.surplusDays)
|
||||
val times = Utils.differYear(
|
||||
System.currentTimeMillis(), Utils.stringToTimestamp(it.expirationTime)
|
||||
)
|
||||
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresDays.text = times[0]
|
||||
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresHours.text = times[1]
|
||||
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresMin.text = times[2]
|
||||
|
||||
@@ -416,9 +416,11 @@ class HomeTrackFragment :
|
||||
private fun shareDeviceState() {
|
||||
val share = MMKVUtil.getInt(MMKVKey.Shared)
|
||||
if (share == ConstantInt.NoShare) {
|
||||
mViewBinding.rvHomePetTrackMenu.visibility=View.VISIBLE
|
||||
mZoneAdapter.showNoDataAddButton(true)
|
||||
mFencesAdapter.showNoDataAddButton(true)
|
||||
} else {
|
||||
mViewBinding.rvHomePetTrackMenu.visibility=View.GONE
|
||||
mZoneAdapter.showNoDataAddButton(false)
|
||||
mFencesAdapter.showNoDataAddButton(false)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/dp_8">
|
||||
android:paddingBottom="@dimen/dp_10">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.roundToInt
|
||||
@@ -125,31 +124,45 @@ class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算2个日期相册多少年,多少月
|
||||
* 计算2个日期相册多少年,多少月,多少天
|
||||
*/
|
||||
fun differYear(startDate: String, endDate: String): Array<Int?> {
|
||||
val result = arrayOfNulls<Int>(2)
|
||||
fun differYear(startTimestamp: Long, endTimestamp: Long): Array<String?> {
|
||||
val result = arrayOfNulls<String>(3)
|
||||
val startDate = formatTime(startTimestamp, DATE_FORMAT_PATTERN_CN)
|
||||
val endDate = formatTime(endTimestamp, DATE_FORMAT_PATTERN_CN)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val period = Period.between(LocalDate.parse(startDate), LocalDate.parse(endDate))
|
||||
result[0] = period.years
|
||||
result[1] = period.months
|
||||
result[0] = "${period.years}"
|
||||
result[1] = "${period.months}"
|
||||
result[2] = "${period.days}"
|
||||
} else {
|
||||
val dfs = SimpleDateFormat(DATE_FORMAT_PATTERN_CN, Locale.getDefault())
|
||||
val sDate = dfs.parse(startDate)
|
||||
val eDate = dfs.parse(endDate)
|
||||
// 得到两者的毫秒数
|
||||
// val between = (eDate.time - sDate.time)
|
||||
val year = eDate.year - sDate.year
|
||||
val month = eDate.month - sDate.month
|
||||
//2021-8-1,2122-1-1
|
||||
if (month < 0) {
|
||||
result[0] = year - 1
|
||||
//取绝对值
|
||||
result[1] = 12 - abs(month)
|
||||
} else {
|
||||
result[0] = year
|
||||
result[1] = month
|
||||
val sDate = dfs.parse(startDate)!!
|
||||
val eDate = dfs.parse(endDate)!!
|
||||
|
||||
val calendarStart = Calendar.getInstance()
|
||||
calendarStart.time = sDate
|
||||
val calendarEnd = Calendar.getInstance()
|
||||
calendarEnd.time = eDate
|
||||
|
||||
var years = calendarEnd[Calendar.YEAR] - calendarStart[Calendar.YEAR]
|
||||
var months = calendarEnd[Calendar.MONTH] - calendarStart[Calendar.MONTH]
|
||||
var days = calendarEnd[Calendar.DAY_OF_MONTH] - calendarStart[Calendar.DAY_OF_MONTH]
|
||||
|
||||
// 调整月份和天数以处理跨年情况
|
||||
if (days < 0) {
|
||||
months--
|
||||
calendarStart.add(Calendar.MONTH, 1) // 将开始日期增加一个月以进行比较
|
||||
days =
|
||||
calendarEnd[Calendar.DAY_OF_MONTH] + (30 - calendarStart[Calendar.DAY_OF_MONTH]) // 假设每个月有30天,简化计算
|
||||
}
|
||||
if (months < 0) {
|
||||
years--
|
||||
months += 12 // 将月份调整为正数以处理跨年情况
|
||||
}
|
||||
result[0] = "$years"
|
||||
result[1] = "$months"
|
||||
result[2] = "$days"
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -195,20 +208,6 @@ class Utils {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 把秒转换为 year month day
|
||||
*/
|
||||
fun getDayToYearMonthDay(second: Long): Array<String> {
|
||||
if (second <= 0) return arrayOf("0", "0", "0")
|
||||
val year = second / 365
|
||||
val month = (second % 365) / 30
|
||||
val day = (second % 365) % 30
|
||||
return arrayOf(
|
||||
fill2Digits(year.toInt()), fill2Digits(month.toInt()), fill2Digits(day.toInt())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param d 需要处理的数字
|
||||
* @param num 保留位数
|
||||
|
||||
Reference in New Issue
Block a user