Skip to content

Commit

Permalink
add 24h time toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
catgirlseraid committed May 16, 2024
1 parent 5d4c57e commit 0c8a69d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class GUIConfig {
@ConfigEditorSlider(minValue = 0.1F, maxValue = 10, minStep = 0.05F)
public float globalScale = 1F;

@Expose
@ConfigOption(name = "Time Format", desc = "Change Skyhanni to use 24h time instead of 12h time.")
@ConfigEditorBoolean
@FeatureToggle
public boolean timeFormat24h = false;

@Expose
@ConfigOption(name = "Discord Rich Presence", desc = "")
@Accordion
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.SkyHanniMod
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
Expand Down Expand Up @@ -36,9 +37,15 @@ value class SimpleTimeMark(private val millis: Long) : Comparable<SimpleTimeMark
}

fun formattedDate(pattern: String): String {
val newPattern = if (SkyHanniMod.feature.gui.timeFormat24h) {
pattern.replace("h", "H").replace("a", "")
} else {
pattern
}

val instant = Instant.ofEpochMilli(millis)
val localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault())
val formatter = DateTimeFormatter.ofPattern(pattern)
val formatter = DateTimeFormatter.ofPattern(newPattern.trim())
return localDateTime.format(formatter)
}

Expand Down

0 comments on commit 0c8a69d

Please sign in to comment.