File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,6 @@ public val DayOfWeek.isoDayNumber: Int get() = ordinal + 1
27
27
* Returns the [DayOfWeek] instance for the given ISO-8601 week day number. Monday is 1, Sunday is 7.
28
28
*/
29
29
public fun DayOfWeek (isoDayNumber : Int ): DayOfWeek {
30
- require(isoDayNumber in 1 .. 7 )
30
+ require(isoDayNumber in 1 .. 7 ) { " Expected ISO day-of-week number in 1..7, got $isoDayNumber " }
31
31
return DayOfWeek .entries[isoDayNumber - 1 ]
32
32
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2019-2024 JetBrains s.r.o. and contributors.
3
+ * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4
+ */
5
+
6
+ package kotlinx.datetime.test
7
+
8
+ import kotlinx.datetime.*
9
+ import kotlin.test.*
10
+
11
+ class DayOfWeekTest {
12
+
13
+ @Test
14
+ fun testDayOfWeek () {
15
+ for (i in 1 .. 7 ) {
16
+ assertEquals(i, DayOfWeek (i).isoDayNumber)
17
+ }
18
+ assertFailsWith<IllegalArgumentException > { DayOfWeek (- 1 ) }
19
+ assertFailsWith<IllegalArgumentException > { DayOfWeek (8 ) }
20
+ assertFailsWith<IllegalArgumentException > { DayOfWeek (Int .MIN_VALUE ) }
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments