Scoop API

scoop:scoop.std:0.1.0

src/datetime/day_of_week.scoop

Selected production source · src/datetime/day_of_week.scoop

1package scoop.datetime
3/**
4 * An ISO weekday, numbered Monday = 1 through Sunday = 7.
5 */
6public enum DayOfWeek : Equals<DayOfWeek>, Compare<DayOfWeek>, Hash, ToString {
7 /**
8 * ISO weekday 1, Monday.
9 */
10 Monday,
11 /**
12 * ISO weekday 2, Tuesday.
13 */
14 Tuesday,
15 /**
16 * ISO weekday 3, Wednesday.
17 */
18 Wednesday,
19 /**
20 * ISO weekday 4, Thursday.
21 */
22 Thursday,
23 /**
24 * ISO weekday 5, Friday.
25 */
26 Friday,
27 /**
28 * ISO weekday 6, Saturday.
29 */
30 Saturday,
31 /**
32 * ISO weekday 7, Sunday.
33 */
34 Sunday
36 /**
37 * The ISO weekday number, Monday = 1 through Sunday = 7.
38 */
39 public val isoDayNumber: Int get() = when (this) {
40 case Monday -> 1; case Tuesday -> 2; case Wednesday -> 3; case Thursday -> 4
41 case Friday -> 5; case Saturday -> 6; case Sunday -> 7
42 }
43 /**
44 * Compares the stored value components for equality.
45 */
46 public override operator fun equals(other: DayOfWeek): Boolean = isoDayNumber == other.isoDayNumber
47 /**
48 * Orders values by their chronological or numeric value; only the result sign is significant.
49 */
50 public override operator fun compareTo(other: DayOfWeek): Long = isoDayNumber.compareTo(other.isoDayNumber)
51 /**
52 * Computes a hash consistent with component equality.
53 */
54 public override fun hash(): Long = isoDayNumber.hash()
55 /**
56 * Returns the English weekday name.
57 */
58 public override fun toString(): String = when (this) {
59 case Monday -> "Monday"; case Tuesday -> "Tuesday"; case Wednesday -> "Wednesday"
60 case Thursday -> "Thursday"; case Friday -> "Friday"; case Saturday -> "Saturday"; case Sunday -> "Sunday"
61 }
62 /**
63 * Value construction and serialization helpers.
64 */
65 public companion object {
66 /**
67 * Converts an ISO weekday number in 1..7; other values throw.
68 */
69 public fun fromIsoDayNumber(isoDayNumber: Int): DayOfWeek = when (isoDayNumber) {
70 case 1 -> Monday; case 2 -> Tuesday; case 3 -> Wednesday; case 4 -> Thursday
71 case 5 -> Friday; case 6 -> Saturday; case 7 -> Sunday
72 case _ -> throw IllegalArgumentException(Some("weekday must be in 1..7"))
73 }
74 }