Scoop API

scoop:scoop.std:0.1.0

src/datetime/month.scoop

Selected production source · src/datetime/month.scoop

1package scoop.datetime
3/**
4 * A Gregorian month, numbered January = 1 through December = 12.
5 */
6public enum Month : Equals<Month>, Compare<Month>, Hash, ToString {
7 /**
8 * Gregorian month 1, January.
9 */
10 January,
11 /**
12 * Gregorian month 2, February.
13 */
14 February,
15 /**
16 * Gregorian month 3, March.
17 */
18 March,
19 /**
20 * Gregorian month 4, April.
21 */
22 April,
23 /**
24 * Gregorian month 5, May.
25 */
26 May,
27 /**
28 * Gregorian month 6, June.
29 */
30 June,
31 /**
32 * Gregorian month 7, July.
33 */
34 July,
35 /**
36 * Gregorian month 8, August.
37 */
38 August,
39 /**
40 * Gregorian month 9, September.
41 */
42 September,
43 /**
44 * Gregorian month 10, October.
45 */
46 October,
47 /**
48 * Gregorian month 11, November.
49 */
50 November,
51 /**
52 * Gregorian month 12, December.
53 */
54 December
56 /**
57 * The Gregorian month number in 1..12.
58 */
59 public val number: Int get() = when (this) {
60 case January -> 1; case February -> 2; case March -> 3; case April -> 4
61 case May -> 5; case June -> 6; case July -> 7; case August -> 8
62 case September -> 9; case October -> 10; case November -> 11; case December -> 12
63 }
64 /**
65 * Compares the stored value components for equality.
66 */
67 public override operator fun equals(other: Month): Boolean = number == other.number
68 /**
69 * Orders values by their chronological or numeric value; only the result sign is significant.
70 */
71 public override operator fun compareTo(other: Month): Long = number.compareTo(other.number)
72 /**
73 * Computes a hash consistent with component equality.
74 */
75 public override fun hash(): Long = number.hash()
76 /**
77 * Returns the English month name.
78 */
79 public override fun toString(): String = when (this) {
80 case January -> "January"; case February -> "February"; case March -> "March"; case April -> "April"
81 case May -> "May"; case June -> "June"; case July -> "July"; case August -> "August"
82 case September -> "September"; case October -> "October"; case November -> "November"; case December -> "December"
83 }
84 /**
85 * Value construction and serialization helpers.
86 */
87 public companion object {
88 /**
89 * Converts a month number in 1..12; other values throw.
90 */
91 public fun fromNumber(number: Int): Month = when (number) {
92 case 1 -> January; case 2 -> February; case 3 -> March; case 4 -> April
93 case 5 -> May; case 6 -> June; case 7 -> July; case 8 -> August
94 case 9 -> September; case 10 -> October; case 11 -> November; case 12 -> December
95 case _ -> throw IllegalArgumentException(Some("month must be in 1..12"))
96 }
97 }