aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
diff options
context:
space:
mode:
authorJ10a1n15 <45315647+j10a1n15@users.noreply.github.com>2024-03-12 19:59:55 +0100
committerGitHub <noreply@github.com>2024-03-12 19:59:55 +0100
commit4352ffb08d4bfffc06adad2a068f375ab9874333 (patch)
treeb8ce745fca8ab82ffa04f6ab87334139a6b7192b /src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
parenteb863d60e82b5541a9f42d2608f61cb97ada209b (diff)
downloadskyhanni-4352ffb08d4bfffc06adad2a068f375ab9874333.tar.gz
skyhanni-4352ffb08d4bfffc06adad2a068f375ab9874333.tar.bz2
skyhanni-4352ffb08d4bfffc06adad2a068f375ab9874333.zip
Feature: CustomScoreboard (#893)
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Co-authored-by: Thunderblade73 <gaidermarkus@gmail.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index d2b269e9a..58bdb2d77 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.mixins.hooks.tryToReplaceScoreboardLine
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
@@ -129,19 +130,36 @@ object TimeUtils {
}.toLong().toDuration(DurationUnit.MILLISECONDS)
}
- fun SkyBlockTime.formatted(): String {
+ fun SkyBlockTime.formatted(
+ dayAndMonthElement: Boolean = true,
+ yearElement: Boolean = true,
+ hoursAndMinutesElement: Boolean = true
+ ): String {
val hour = if (this.hour > 12) this.hour - 12 else this.hour
- val timeOfDay = if (this.hour > 11) "pm" else "am" // hooray for 12-hour clocks
- var minute = this.minute.toString()
- if (minute.length != 2) {
- minute = minute.padStart(2, '0')
- }
-
+ val timeOfDay = if (this.hour > 11) "pm" else "am"
+ val minute = this.minute.toString().padStart(2, '0')
val month = SkyBlockTime.monthName(this.month)
val day = this.day
val daySuffix = SkyBlockTime.daySuffix(day)
val year = this.year
- return "$month $day$daySuffix, Year $year $hour:${minute}$timeOfDay" // Early Winter 1st Year 300, 12:03pm
+
+ val datePart = when {
+ yearElement -> "$month $day$daySuffix, Year $year"
+ dayAndMonthElement -> "$month $day$daySuffix"
+ else -> ""
+ }
+ val timePart = if (hoursAndMinutesElement) "$hour:$minute$timeOfDay" else ""
+
+ /**
+ * We replace the line here, because the user might want color month names
+ */
+ return tryToReplaceScoreboardLine(
+ if (datePart.isNotEmpty() && timePart.isNotEmpty()) {
+ "$datePart, $timePart"
+ } else {
+ "$datePart$timePart".trim()
+ }
+ ) ?: ""
}
fun getCurrentLocalDate(): LocalDate = LocalDate.now(ZoneId.of("UTC"))