aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
diff options
context:
space:
mode:
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"))