From fed73a275bcd73a8ea80e6d967f309f7fb29e3f9 Mon Sep 17 00:00:00 2001 From: Ian Clarke Date: Sat, 28 Oct 2023 11:19:09 -0500 Subject: [PATCH] fix ordinal --- .../org/freenet/website/pages/blog/blogPage.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/freenet/website/pages/blog/blogPage.kt b/src/main/kotlin/org/freenet/website/pages/blog/blogPage.kt index 4848780..176aaaf 100644 --- a/src/main/kotlin/org/freenet/website/pages/blog/blogPage.kt +++ b/src/main/kotlin/org/freenet/website/pages/blog/blogPage.kt @@ -76,18 +76,20 @@ private fun formatForUrl(title: String): String { } -private fun getOrdinalWithSuperscript(n: Int): String { +private fun getOrdinal(n: Int): String { val suffixes = arrayOf("th", "st", "nd", "rd") - val suffix = when (n % 100) { - 11, 12, 13 -> "th" - else -> suffixes.getOrNull((n % 10).coerceIn(1..3) - 1).orEmpty() + return when (n % 100) { + 11, 12, 13 -> n.toString() + "th" + else -> { + val lastDigit = n % 10 + n.toString() + suffixes.getOrNull(lastDigit.coerceIn(1..3) - 1).orEmpty() + } } - return "${n}${suffix}" } fun Instant.asFriendlyDate(): String { val localDate = this.atZone(ZoneId.systemDefault()).toLocalDate() - val day = getOrdinalWithSuperscript(localDate.dayOfMonth) + val day = getOrdinal(localDate.dayOfMonth) val month = localDate.month.getDisplayName(TextStyle.FULL, Locale.US) val year = localDate.year return "$day $month, $year"