mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-04 09:45:34 +08:00
Fix GithubReleaseTool to LocalTime
This commit is contained in:
@@ -24,11 +24,15 @@ package com.fankes.coloros.notify.utils.tool
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.icu.text.SimpleDateFormat
|
||||||
|
import android.icu.util.Calendar
|
||||||
|
import android.icu.util.TimeZone
|
||||||
import com.fankes.coloros.notify.utils.factory.*
|
import com.fankes.coloros.notify.utils.factory.*
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 Github Release 最新版本工具类
|
* 获取 Github Release 最新版本工具类
|
||||||
@@ -62,7 +66,7 @@ object GithubReleaseTool {
|
|||||||
name = getString("name"),
|
name = getString("name"),
|
||||||
htmlUrl = getString("html_url"),
|
htmlUrl = getString("html_url"),
|
||||||
content = getString("body"),
|
content = getString("body"),
|
||||||
date = getString("published_at").replace(oldValue = "T", newValue = " ").replace(oldValue = "Z", newValue = "")
|
date = getString("published_at").localTime()
|
||||||
).apply {
|
).apply {
|
||||||
fun showUpdate() = context.showDialog {
|
fun showUpdate() = context.showDialog {
|
||||||
title = "最新版本 $name"
|
title = "最新版本 $name"
|
||||||
@@ -112,6 +116,18 @@ object GithubReleaseTool {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化时间为本地时区
|
||||||
|
* @return [String] 本地时区时间
|
||||||
|
*/
|
||||||
|
private fun String.localTime() = replace(oldValue = "T", newValue = " ").replace(oldValue = "Z", newValue = "").let {
|
||||||
|
runCatching {
|
||||||
|
val local = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT).apply { timeZone = Calendar.getInstance().timeZone }
|
||||||
|
val current = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT).apply { timeZone = TimeZone.getTimeZone("GMT") }
|
||||||
|
local.format(current.parse(it))
|
||||||
|
}.getOrNull() ?: it
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Github Release bean
|
* Github Release bean
|
||||||
* @param name 版本名称
|
* @param name 版本名称
|
||||||
|
Reference in New Issue
Block a user