From 4352ffb08d4bfffc06adad2a068f375ab9874333 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:59:55 +0100 Subject: Feature: CustomScoreboard (#893) Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Co-authored-by: Thunderblade73 Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/utils/TimeUtils.kt | 34 +++++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt') 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")) -- cgit