@@ -14,6 +14,7 @@ class DateTimePeriodSamples {
14
14
15
15
@Test
16
16
fun construction () {
17
+ // Constructing a DateTimePeriod using its constructor function
17
18
val period = DateTimePeriod (years = 5 , months = 21 , days = 36 , seconds = 3601 )
18
19
check(period.years == 6 ) // 5 years + (21 months / 12)
19
20
check(period.months == 9 ) // 21 months % 12
@@ -27,13 +28,15 @@ class DateTimePeriodSamples {
27
28
28
29
@Test
29
30
fun simpleParsingAndFormatting () {
31
+ // Parsing and formatting a DateTimePeriod
30
32
val string = " -P2M-3DT-4H"
31
33
val period = DateTimePeriod .parse(string)
32
34
check(period.toString() == " P-2M3DT4H" )
33
35
}
34
36
35
37
@Test
36
38
fun valueNormalization () {
39
+ // Reading the normalized values that make up a DateTimePeriod
37
40
val period = DateTimePeriod (
38
41
years = - 12 , months = 122 , days = - 1440 ,
39
42
hours = 400 , minutes = - 80 , seconds = 123 , nanoseconds = - 123456789
@@ -52,13 +55,15 @@ class DateTimePeriodSamples {
52
55
53
56
@Test
54
57
fun toStringSample () {
58
+ // Formatting a DateTimePeriod to a string
55
59
check(DateTimePeriod (years = 1 , months = 2 , days = 3 , hours = 4 , minutes = 5 , seconds = 6 , nanoseconds = 7 ).toString() == " P1Y2M3DT4H5M6.000000007S" )
56
60
check(DateTimePeriod (months = 14 , days = - 16 , hours = 5 ).toString() == " P1Y2M-16DT5H" )
57
61
check(DateTimePeriod (months = - 2 , days = - 16 , hours = - 5 ).toString() == " -P2M16DT5H" )
58
62
}
59
63
60
64
@Test
61
65
fun parsing () {
66
+ // Parsing a string representation of a DateTimePeriod
62
67
DateTimePeriod .parse(" P1Y2M3DT4H5M6.000000007S" ).apply {
63
68
check(years == 1 )
64
69
check(months == 2 )
@@ -84,6 +89,7 @@ class DateTimePeriodSamples {
84
89
85
90
@Test
86
91
fun constructorFunction () {
92
+ // Constructing a DateTimePeriod using its constructor function
87
93
val dateTimePeriod = DateTimePeriod (months = 16 , days = - 60 , hours = 16 , minutes = - 61 )
88
94
check(dateTimePeriod.years == 1 ) // months overflowed to years
89
95
check(dateTimePeriod.months == 4 ) // 16 months % 12
@@ -96,6 +102,7 @@ class DateTimePeriodSamples {
96
102
97
103
@Test
98
104
fun durationToDateTimePeriod () {
105
+ // Converting a Duration to a DateTimePeriod that only has time-based components
99
106
check(130 .minutes.toDateTimePeriod() == DateTimePeriod (minutes = 130 ))
100
107
check(2 .days.toDateTimePeriod() == DateTimePeriod (days = 0 , hours = 48 ))
101
108
}
@@ -104,6 +111,7 @@ class DateTimePeriodSamples {
104
111
105
112
@Test
106
113
fun simpleParsingAndFormatting () {
114
+ // Parsing and formatting a DatePeriod
107
115
val datePeriod1 = DatePeriod (years = 1 , days = 3 )
108
116
val string = datePeriod1.toString()
109
117
check(string == " P1Y3D" )
@@ -113,6 +121,7 @@ class DateTimePeriodSamples {
113
121
114
122
@Test
115
123
fun construction () {
124
+ // Constructing a DatePeriod using its constructor
116
125
val datePeriod = DatePeriod (years = 1 , months = 16 , days = 60 )
117
126
check(datePeriod.years == 2 ) // 1 year + (16 months / 12)
118
127
check(datePeriod.months == 4 ) // 16 months % 12
@@ -126,6 +135,7 @@ class DateTimePeriodSamples {
126
135
127
136
@Test
128
137
fun parsing () {
138
+ // Parsing a string representation of a DatePeriod
129
139
// ISO duration strings are supported:
130
140
val datePeriod = DatePeriod .parse(" P1Y16M60D" )
131
141
check(datePeriod == DatePeriod (years = 2 , months = 4 , days = 60 ))
0 commit comments