Skip to content

Commit 4665f88

Browse files
committed
Update the docs
1 parent cdf9e1e commit 4665f88

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

core/common/src/LocalDate.kt

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public expect class LocalDate : Comparable<LocalDate> {
8080
* - [month] `1..12`
8181
* - [day] `1..31`, the upper bound can be less, depending on the month
8282
*
83+
* Use `LocalDate(year, month, day) to throw an exception
84+
* instead of returning `null` when the parameters are invalid.
85+
*
8386
* @sample kotlinx.datetime.test.samples.LocalDateSamples.createOrNullMonthNumber
8487
*/
8588
public fun createOrNull(year: Int, month: Int, day: Int): LocalDate?
@@ -94,6 +97,9 @@ public expect class LocalDate : Comparable<LocalDate> {
9497
* - [month] all values of the [Month] enum
9598
* - [day] `1..31`, the upper bound can be less, depending on the month
9699
*
100+
* Use `LocalDate(year, month, day) to throw an exception
101+
* instead of returning `null` when the parameters are invalid.
102+
*
97103
* @sample kotlinx.datetime.test.samples.LocalDateSamples.createOrNull
98104
*/
99105
public fun createOrNull(year: Int, month: Month, day: Int): LocalDate?
@@ -205,6 +211,8 @@ public expect class LocalDate : Comparable<LocalDate> {
205211
*
206212
* @throws IllegalArgumentException if any parameter is out of range or if [day] is invalid for the
207213
* given [month] and [year].
214+
* @see createOrNull for a version that returns `null` instead of throwing an exception
215+
* when the parameters are invalid.
208216
* @sample kotlinx.datetime.test.samples.LocalDateSamples.constructorFunctionMonthNumber
209217
*/
210218
public constructor(year: Int, month: Int, day: Int)
@@ -220,6 +228,8 @@ public expect class LocalDate : Comparable<LocalDate> {
220228
*
221229
* @throws IllegalArgumentException if any parameter is out of range or if [day] is invalid for the
222230
* given [month] and [year].
231+
* @see createOrNull for a version that returns `null` instead of throwing an exception
232+
* when the parameters are invalid.
223233
* @sample kotlinx.datetime.test.samples.LocalDateSamples.constructorFunction
224234
*/
225235
public constructor(year: Int, month: Month, day: Int)

core/common/src/LocalDateTime.kt

+9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ public expect class LocalDateTime : Comparable<LocalDateTime> {
130130
* - [second] `0..59`
131131
* - [nanosecond] `0..999_999_999`
132132
*
133+
* Use `LocalDateTime(year, month, day, hour, minute, second, nanosecond)`
134+
* to throw an exception instead of returning `null` when the parameters are invalid.
135+
*
133136
* @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.createOrNull
134137
*/
135138
public fun createOrNull(
@@ -156,6 +159,9 @@ public expect class LocalDateTime : Comparable<LocalDateTime> {
156159
* - [second] `0..59`
157160
* - [nanosecond] `0..999_999_999`
158161
*
162+
* Use `LocalDateTime(year, month, day, hour, minute, second, nanosecond)`
163+
* to throw an exception instead of returning `null` when the parameters are invalid.
164+
*
159165
* @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.createOrNullWithMonth
160166
*/
161167
public fun createOrNull(
@@ -268,6 +274,7 @@ public expect class LocalDateTime : Comparable<LocalDateTime> {
268274
*
269275
* @throws IllegalArgumentException if any parameter is out of range
270276
* or if [day] is invalid for the given [monthNumber] and [year].
277+
* @see createOrNull for a version that returns `null` instead of throwing an exception when the parameters are invalid.
271278
*
272279
* @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.constructorFunctionWithMonthNumber
273280
*/
@@ -296,6 +303,7 @@ public expect class LocalDateTime : Comparable<LocalDateTime> {
296303
*
297304
* @throws IllegalArgumentException if any parameter is out of range,
298305
* or if [day] is invalid for the given [month] and [year].
306+
* @see createOrNull for a version that returns `null` instead of throwing an exception when the parameters are invalid.
299307
*
300308
* @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.constructorFunction
301309
*/
@@ -312,6 +320,7 @@ public expect class LocalDateTime : Comparable<LocalDateTime> {
312320
/**
313321
* Constructs a [LocalDateTime] instance by combining the given [date] and [time] parts.
314322
*
323+
* @see createOrNull for a version that returns `null` instead of throwing an exception when the parameters are invalid.
315324
* @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.fromDateAndTime
316325
*/
317326
public constructor(date: LocalDate, time: LocalTime)

core/common/src/LocalTime.kt

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public expect class LocalTime : Comparable<LocalTime> {
9494
* - [second] `0..59`
9595
* - [nanosecond] `0..999_999_999`
9696
*
97+
* Use `LocalTime(hour, minute, second, nanosecond)`
98+
* to throw an exception instead of returning `null` when the parameters are invalid.
99+
*
97100
* @sample kotlinx.datetime.test.samples.LocalTimeSamples.createOrNull
98101
*/
99102
public fun createOrNull(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0): LocalTime?
@@ -244,6 +247,7 @@ public expect class LocalTime : Comparable<LocalTime> {
244247
* - [nanosecond] `0..999_999_999`
245248
*
246249
* @throws IllegalArgumentException if any parameter is out of range.
250+
* @see createOrNull for a version that returns `null` instead of throwing an exception when the parameters are invalid.
247251
* @sample kotlinx.datetime.test.samples.LocalTimeSamples.constructorFunction
248252
*/
249253
public constructor(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0)

core/common/src/UtcOffset.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ public expect class UtcOffset {
8989
* However, the non-null component of the highest order can exceed these bounds,
9090
* for example, `UtcOffset.createOrNull(minutes = 241)` and `UtcOffset.createOrNull(seconds = -3600)` are both valid.
9191
*
92-
* @return the [UtcOffset] with the specified components, or `null` if the components are invalid
93-
* or the resulting `UtcOffset` value is outside of range `±18:00`.
92+
* Use `UtcOffset(hours, minutes, seconds)` to throw an exception instead of returning `null`
93+
* when the parameters are invalid.
94+
*
9495
* @sample kotlinx.datetime.test.samples.UtcOffsetSamples.createOrNull
9596
*/
9697
public fun createOrNull(hours: Int? = null, minutes: Int? = null, seconds: Int? = null): UtcOffset?
@@ -228,6 +229,7 @@ public fun UtcOffset.format(format: DateTimeFormat<UtcOffset>): String = format.
228229
* @throws IllegalArgumentException if a component exceeds its bounds when a higher order component is specified.
229230
* @throws IllegalArgumentException if components have different signs.
230231
* @throws IllegalArgumentException if the resulting `UtcOffset` value is outside of range `±18:00`.
232+
* @see UtcOffset.createOrNull for a version that returns `null` instead of throwing an exception when the parameters are invalid.
231233
* @sample kotlinx.datetime.test.samples.UtcOffsetSamples.constructorFunction
232234
*/
233235
public expect fun UtcOffset(hours: Int? = null, minutes: Int? = null, seconds: Int? = null): UtcOffset

0 commit comments

Comments
 (0)