From 63a35d5b3a4243eaeab59efafa7c5045c0611409 Mon Sep 17 00:00:00 2001 From: NovaFox161 Date: Wed, 8 Dec 2021 16:58:37 -0600 Subject: [PATCH] Display day of week in overview, eg `Wednesday - 08 December 2021` --- .../discal/client/message/embed/CalendarEmbed.kt | 2 +- .../org/dreamexposure/discal/core/enums/time/TimeFormat.kt | 6 +++--- .../discal/core/extensions/InstantExtension.kt | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/message/embed/CalendarEmbed.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/message/embed/CalendarEmbed.kt index 63d5336d..8ca6a226 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/message/embed/CalendarEmbed.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/message/embed/CalendarEmbed.kt @@ -55,7 +55,7 @@ object CalendarEmbed : EmbedMaker { // Show events events.forEach { date -> - val title = date.key.toInstant().humanReadableDate(calendar.timezone, settings.timeFormat, true) + val title = date.key.toInstant().humanReadableDate(calendar.timezone, settings.timeFormat, longDay = true) // sort events val sortedEvents = date.value.sortedBy { it.start } diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/enums/time/TimeFormat.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/enums/time/TimeFormat.kt index 2b328be4..46f410bd 100644 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/enums/time/TimeFormat.kt +++ b/core/src/main/kotlin/org/dreamexposure/discal/core/enums/time/TimeFormat.kt @@ -9,9 +9,9 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @Serializable(with = TimeFormatAsIntSerializer::class) -enum class TimeFormat(val value: Int = 1, val full: String, val date: String, val longDate: String, val time: String) { - TWENTY_FOUR_HOUR(1, "LLLL dd yyyy '@' HH:mm", "yyyy/MM/dd", "dd LLLL yyyy", "HH:mm"), - TWELVE_HOUR(2, "LLLL dd yyyy '@' hh:mm a", "yyyy/MM/dd", "dd LLLL yyyy", "hh:mm a"); +enum class TimeFormat(val value: Int = 1, val full: String, val date: String, val longDate: String, val time: String, val dayOfWeek: String) { + TWENTY_FOUR_HOUR(1, "LLLL dd yyyy '@' HH:mm", "yyyy/MM/dd", "dd LLLL yyyy", "HH:mm", "EEEE '-' dd LLLL yyyy"), + TWELVE_HOUR(2, "LLLL dd yyyy '@' hh:mm a", "yyyy/MM/dd", "dd LLLL yyyy", "hh:mm a", "EEEE '-' dd LLLL yyyy"); companion object { fun isValid(i: Int): Boolean { diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/extensions/InstantExtension.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/extensions/InstantExtension.kt index b674f03a..3025fc35 100644 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/extensions/InstantExtension.kt +++ b/core/src/main/kotlin/org/dreamexposure/discal/core/extensions/InstantExtension.kt @@ -12,8 +12,9 @@ fun Instant.humanReadableFull(timezone: ZoneId, format: TimeFormat): String { return DateTimeFormatter.ofPattern(format.full).withZone(timezone).format(this) } -fun Instant.humanReadableDate(timezone: ZoneId, format: TimeFormat, long: Boolean): String { - return if (long) DateTimeFormatter.ofPattern(format.longDate).withZone(timezone).format(this) +fun Instant.humanReadableDate(timezone: ZoneId, format: TimeFormat, long: Boolean = true, longDay: Boolean = false): String { + return if (long && longDay) DateTimeFormatter.ofPattern(format.dayOfWeek).withZone(timezone).format(this) + else if (long) DateTimeFormatter.ofPattern(format.longDate).withZone(timezone).format(this) else DateTimeFormatter.ofPattern(format.date).withZone(timezone).format(this) }