Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timezone config option #240

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Found under `[search]`

`purgePermissionLevel` [Default: 4] controls the permission level required to run the purge command

`timeZone` [Default: "UTC"] sets the timezone to display timestamps in when hovered.
This uses the Java TimeZone format. You can provide offsets ("UTC", "UTC+3"), but the "continent/region" format is preferred. A full list can be found [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).

### Message theme

Found under `[color]`
Expand Down Expand Up @@ -64,6 +67,8 @@ queueCheckDelaySec = 10
pageSize = 8
# Permission level for purge command
purgePermissionLevel = 4
# Time zone to display timestamps in. EX: "UTC", "UTC+1", "America/Los_Angeles"
timeZone = "UTC"

[color]
# Colors in hex format
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.quiltservertools.ledger.config

import com.uchuhimo.konf.ConfigSpec
import java.time.ZoneId

object SearchSpec : ConfigSpec() {
val pageSize by required<Int>()
val purgePermissionLevel by required<Int>()
val timeZone by required<ZoneId>()
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.github.quiltservertools.ledger.utility

import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.actionutils.SearchResults
import com.github.quiltservertools.ledger.config.SearchSpec
import com.github.quiltservertools.ledger.database.DatabaseManager
import com.github.quiltservertools.ledger.network.Networking.hasNetworking
import com.github.quiltservertools.ledger.network.packet.action.ActionPacket
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.*
import net.minecraft.text.ClickEvent
import net.minecraft.text.HoverEvent
import net.minecraft.text.MutableText
import net.minecraft.text.Style
import net.minecraft.text.Text
import java.time.Duration
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.*
import kotlin.time.ExperimentalTime
import kotlin.time.toKotlinDuration

Expand Down Expand Up @@ -125,7 +130,7 @@ object MessageUtils {
val message = Text.translatable("text.ledger.action_message.time_diff", text)

val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)
val timeMessage = formatter.format(time.atZone(TimeZone.getDefault().toZoneId())).literal()
val timeMessage = formatter.format(time.atZone(Ledger.config[SearchSpec.timeZone])).literal()

message.styled {
it.withHoverEvent(
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/ledger.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ autoPurgeDays = -1
pageSize = 8
# Permission level for purge command
purgePermissionLevel = 4
# Time zone to display timestamps in (UTC, UTC+1, America/Los_Angeles)
timeZone = "UTC"

[color]
# Colors in hex format
Expand Down
Loading