Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Add Norwegian locale and corresponding test (failing as pr issue #146) #147

Merged
merged 8 commits into from Oct 27, 2020
6 changes: 3 additions & 3 deletions klock/src/commonMain/kotlin/com/soywiz/klock/KlockLocale.kt
Expand Up @@ -84,11 +84,11 @@ abstract class KlockLocale {
override val firstDayOfWeek: DayOfWeek = DayOfWeek.Sunday

override val daysOfWeek: List<String> = listOf(
"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
)
override val months: List<String> = listOf(
"january", "february", "march", "april", "may", "june",
"july", "august", "september", "october", "november", "december"
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
)

override val formatTimeMedium = format("h:mm:ss a")
Expand Down
Expand Up @@ -132,14 +132,14 @@ data class PatternDateFormat @JvmOverloads constructor(
for (name in chunks) {
val nlen = name.length
out += when (name) {
"E", "EE", "EEE" -> realLocale.daysOfWeekShort[utc.dayOfWeek.index0].capitalize()
"EEEE", "EEEEE", "EEEEEE" -> realLocale.daysOfWeek[utc.dayOfWeek.index0].capitalize()
"E", "EE", "EEE" -> DayOfWeek[utc.dayOfWeek.index0].localShortName(realLocale)
"EEEE", "EEEEE", "EEEEEE" -> DayOfWeek[utc.dayOfWeek.index0].localName(realLocale)
"z", "zzz" -> dd.offset.timeZone
"d", "dd" -> utc.dayOfMonth.padded(nlen)
"M", "MM" -> utc.month1.padded(nlen)
"MMM" -> realLocale.months[utc.month0].substr(0, 3).capitalize()
"MMMM" -> realLocale.months[utc.month0].capitalize()
"MMMMM" -> realLocale.months[utc.month0].substr(0, 1).capitalize()
"MMM" -> Month[utc.month1].localName(realLocale).substr(0, 3)
"MMMM" -> Month[utc.month1].localName(realLocale)
"MMMMM" -> Month[utc.month1].localName(realLocale).substr(0, 1)
"y" -> utc.yearInt
"yy" -> (utc.yearInt % 100).padded(2)
"yyy" -> (utc.yearInt % 1000).padded(3)
Expand Down Expand Up @@ -212,7 +212,7 @@ data class PatternDateFormat @JvmOverloads constructor(
}
"d", "dd" -> day = value.toInt()
"M", "MM" -> month = value.toInt()
"MMM" -> month = realLocale.monthsShort.indexOf(value.toLowerCase()) + 1
"MMM" -> month = realLocale.monthsShort.indexOf(value) + 1
"y", "yyyy", "YYYY" -> fullYear = value.toInt()
"yy" -> if (doThrow) throw RuntimeException("Not guessing years from two digits.") else return null
"yyy" -> fullYear = value.toInt() + if (value.toInt() < 800) 2000 else 1000 // guessing year...
Expand Down Expand Up @@ -257,7 +257,7 @@ data class PatternDateFormat @JvmOverloads constructor(
}
}
}
"MMMM" -> month = realLocale.months.indexOf(value.toLowerCase()) + 1
"MMMM" -> month = realLocale.months.indexOf(value) + 1
"MMMMM" -> if (doThrow) throw RuntimeException("Not possible to get the month from one letter.") else return null
"a" -> isPm = value == "pm"
else -> {
Expand Down
6 changes: 3 additions & 3 deletions klock/src/commonMain/kotlin/com/soywiz/klock/locale/de.kt
Expand Up @@ -15,11 +15,11 @@ open class GermanKlockLocale : KlockLocale() {
override val firstDayOfWeek: DayOfWeek = DayOfWeek.Monday

override val daysOfWeek = listOf(
"sonntag", "montag", "dienstag", "mittwoch", "donnerstag", "freitag", "samstag"
"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"
)
override val months = listOf(
"januar", "februar", "märz", "april", "mai", "juni",
"juli", "august", "september", "oktober", "november", "dezember"
"Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember"
)

override val formatDateTimeMedium = format("dd.MM.y HH:mm:ss")
Expand Down
46 changes: 46 additions & 0 deletions klock/src/commonMain/kotlin/com/soywiz/klock/locale/nb.kt
@@ -0,0 +1,46 @@
package com.soywiz.klock.locale

import com.soywiz.klock.DayOfWeek
import com.soywiz.klock.KlockLocale

val KlockLocale.Companion.norwegian get() = NorwegianKlockLocale

open class NorwegianKlockLocale : KlockLocale() {

companion object : NorwegianKlockLocale()

override val ISO639_1 = "nb"

override val firstDayOfWeek = DayOfWeek.Monday

override val daysOfWeek = listOf(
"søndag", "mandag", "tirsdag", "onsdag", "torsdag", "fredag", "lørdag"
)

override val months = listOf(
"januar",
"februar",
"mars",
"april",
"mai",
"juni",
"juli",
"august",
"september",
"oktober",
"november",
"desember"
)

override val formatDateTimeMedium = format("dd.MM.y HH:mm:ss")
override val formatDateTimeShort = format("dd.MM.yy HH:mm")

override val formatDateFull = format("EEEE, d. MMMM y")
override val formatDateLong = format("d. MMMM y")
override val formatDateMedium = format("dd.MM.y")
override val formatDateShort = format("dd.MM.yy")

override val formatTimeMedium = format("HH:mm:ss")
override val formatTimeShort = format("HH:mm")

}
12 changes: 6 additions & 6 deletions klock/src/commonMain/kotlin/com/soywiz/klock/locale/uk.kt
Expand Up @@ -13,13 +13,13 @@ open class UkrainianKlockLocale : KlockLocale() {

override val firstDayOfWeek: DayOfWeek = DayOfWeek.Monday

override val daysOfWeek = listOf(
"неділя", "понеділок", "вівторок", "середа", "четвер", "п'ятниця", "субота"
)
override val daysOfWeek = listOf(
"неділя", "понеділок", "вівторок", "середа", "четвер", "п'ятниця", "субота"
)

override val daysOfWeekShort = listOf(
"нд", "пн", "вт", "ср", "чт", "пт", "сб"
)
override val daysOfWeekShort = listOf(
"нд", "пн", "вт", "ср", "чт", "пт", "сб"
)

override val months = listOf(
"січня", "лютого", "березня", "квітня", "травня", "червня",
Expand Down
Expand Up @@ -11,11 +11,11 @@ class KlockLocaleTest {
fun testSpanishLocale() {
assertEquals(
"""
Mié, 13 Mar 2019 21:36:45 UTC
mié, 13 mar 2019 21:36:45 UTC
13/03/2019 21:36:45
13/03/19 21:36
Miércoles, 13 de Marzo de 2019
13 de Marzo de 2019
miércoles, 13 de marzo de 2019
13 de marzo de 2019
13/03/2019
13/03/19
21:36:45
Expand All @@ -29,12 +29,12 @@ class KlockLocaleTest {
fun testFrenchLocale() {
assertEquals(
"""
Mer, 13 Mar 2019 21:36:45 UTC
13 Mar 2019 21:36:45
mer, 13 mar 2019 21:36:45 UTC
13 mar 2019 21:36:45
13/03/2019 21:36
Mercredi 13 Mars 2019
13 Mars 2019
13 Mar 2019
mercredi 13 mars 2019
13 mars 2019
13 mar 2019
13/03/2019
21:36:45
21:36
Expand All @@ -61,6 +61,24 @@ class KlockLocaleTest {
)
}

@Test
fun testNorwegianLocale() {
assertEquals(
"""
ons, 13 mar 2019 21:36:45 UTC
13.03.2019 21:36:45
13.03.19 21:36
onsdag, 13. mars 2019
13. mars 2019
13.03.2019
13.03.19
21:36:45
21:36
""".trimIndent(),
multiFormat(NorwegianKlockLocale, KlockLocale.norwegian)
)
}

@Test
fun testJapaneseLocale() {
assertEquals(
Expand All @@ -83,12 +101,12 @@ class KlockLocaleTest {
fun testDutchLocale() {
assertEquals(
"""
Woe, 13 Maa 2019 21:36:45 UTC
13 Maa 2019 21:36:45
woe, 13 maa 2019 21:36:45 UTC
13 maa 2019 21:36:45
13-03-19 21:36
Woensdag 13 Maart 2019
13 Maart 2019
13 Maa 2019
woensdag 13 maart 2019
13 maart 2019
13 maa 2019
13-03-2019
21:36:45
21:36
Expand All @@ -101,12 +119,12 @@ class KlockLocaleTest {
fun testPortugueseLocale() {
assertEquals(
"""
Qua, 13 Mar 2019 21:36:45 UTC
13 de Mar de 2019 21:36:45
qua, 13 mar 2019 21:36:45 UTC
13 de mar de 2019 21:36:45
13/03/2019 21:36
Quarta-feira, 13 de Março de 2019
13 de Março de 2019
13 de Mar de 2019
quarta-feira, 13 de março de 2019
13 de março de 2019
13 de mar de 2019
13/03/2019
21:36:45
21:36
Expand All @@ -119,12 +137,12 @@ class KlockLocaleTest {
fun testRussianLocale() {
assertEquals(
"""
Ср, 13 Мар 2019 21:36:45 UTC
13 Мар 2019 г. 21:36:45
ср, 13 мар 2019 21:36:45 UTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The day of the week ("ср") should start with an upper letter ("Ср")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Can you confirm that all weekdays in two-letter short form should start with an upper case letter?

override val daysOfWeekShort = listOf(
		"вс", "пн", "вт", "ср", "чт", "пт", "сб"
	)

Can you type them here so it gets correct?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like that?

override val daysOfWeekShort = listOf(
    "Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"
)

13 мар 2019 г. 21:36:45
13.03.2019 21:36
Среда, 13 Марта 2019 г.
13 Марта 2019 г.
13 Мар 2019 г.
среда, 13 марта 2019 г.
Dambakk marked this conversation as resolved.
Show resolved Hide resolved
13 марта 2019 г.
13 мар 2019 г.
13.03.2019
21:36:45
21:36
Expand Down Expand Up @@ -173,12 +191,12 @@ class KlockLocaleTest {
fun testUkrainianLocale() {
assertEquals(
"""
Ср, 13 Бер 2019 21:36:45 UTC
13 Бер 2019 р. 21:36:45
ср, 13 бер 2019 21:36:45 UTC

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Ukrainian, the day of the week should start with an upper letter: "Ср" instead of "ср".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
Can you confirm that this is the correct two-letter short form for weekdays in Ukrainian?

override val daysOfWeekShort = listOf(
    "нд", "пн", "вт", "Ср", "чт", "пт", "сб"
)

13 бер 2019 р. 21:36:45
13.03.2019 21:36
Середа, 13 Березня 2019 р.
13 Березня 2019 р.
13 Бер 2019 р.
середа, 13 березня 2019 р.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full format of the day of the week should start with an upper letter as well.
"Середа" instead of "середа"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
Can you confirm that these weekdays are correct?

override val daysOfWeek = listOf(
    "неділя", "понеділок", "вівторок", "Середа", "четвер", "п'ятниця", "субота"
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cross-checking with how Java DateTime does formatting and gets an exception:

Expected :середа, 18 січня 1995 21:36:45 // <- Java
Actual   :Середа, 18 січня 1995 21:36:45 // <- Klock

Can you confirm that Java is wrong and that it should be uppercased?

13 березня 2019 р.
13 бер 2019 р.
13.03.2019
21:36:45
21:36
Expand Down Expand Up @@ -226,7 +244,7 @@ class KlockLocaleTest {
fun testTemporalSetDefault() {
assertEquals("Wed, 13 Mar 2019 21:36:45 UTC", date.toString())
KlockLocale.setTemporarily(KlockLocale.spanish) {
assertEquals("Mié, 13 Mar 2019 21:36:45 UTC", date.toString())
assertEquals("mié, 13 mar 2019 21:36:45 UTC", date.toString())
}
assertEquals("Wed, 13 Mar 2019 21:36:45 UTC", date.toString())
}
Expand Down