Fix #3468 - Timed Mute (#3544)

This commit is contained in:
Dane Evans 2025-10-30 16:48:06 +11:00 committed by GitHub
parent c482bd0aaf
commit 54104b00ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 77 additions and 4 deletions

View file

@ -21,6 +21,8 @@ import java.text.DateFormat
import java.util.Date
import java.util.concurrent.TimeUnit
private const val ONLINE_WINDOW_HOURS = 2
// return time if within 24 hours, otherwise date
fun getShortDate(time: Long): String? {
val date = if (time != 0L) Date(time) else return null
@ -62,5 +64,21 @@ private fun formatUptime(seconds: Long): String {
.joinToString(" ")
}
@Suppress("MagicNumber")
fun onlineTimeThreshold() = (System.currentTimeMillis() / 1000 - 2 * 60 * 60).toInt()
fun onlineTimeThreshold(): Int {
val currentSeconds = System.currentTimeMillis() / TimeUnit.SECONDS.toMillis(1)
return (currentSeconds - TimeUnit.HOURS.toSeconds(ONLINE_WINDOW_HOURS.toLong())).toInt()
}
/**
* Calculates the remaining mute time in days and hours.
*
* @param remainingMillis The remaining time in milliseconds
* @return Pair of (days, hours), where days is Int and hours is Double
*/
fun formatMuteRemainingTime(remainingMillis: Long): Pair<Int, Double> {
if (remainingMillis <= 0) return Pair(0, 0.0)
val totalHours = remainingMillis.toDouble() / TimeUnit.HOURS.toMillis(1)
val days = (totalHours / TimeUnit.DAYS.toHours(1)).toInt()
val hours = totalHours % TimeUnit.DAYS.toHours(1)
return Pair(days, hours)
}