UtcOffset

actual fun UtcOffset(hours: Int? = null, minutes: Int? = null, seconds: Int? = null): UtcOffset(source)
expect fun UtcOffset(hours: Int? = null, minutes: Int? = null, seconds: Int? = null): UtcOffset(source)

Constructs a UtcOffset from hours, minutes, and seconds components.

All components must have the same sign. Otherwise, IllegalArgumentException will be thrown.

The bounds are checked: it is invalid to pass something other than ±[0; 59] as the number of seconds or minutes; IllegalArgumentException will be thrown if this rule is violated. For example, UtcOffset(hours = 3, minutes = 61) is invalid.

However, the non-null component of the highest order can exceed these bounds, for example, UtcOffset(minutes = 241) and UtcOffset(seconds = -3600) are both valid.

Throws

if the resulting UtcOffset value is outside of range ±18:00.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   // Using the constructor function to create UtcOffset values
check(UtcOffset(hours = 3, minutes = 30).totalSeconds == 12600)
check(UtcOffset(seconds = -3600) == UtcOffset(hours = -1))
try {
    UtcOffset(hours = 1, minutes = 60)
    fail("Expected IllegalArgumentException")
} catch (e: IllegalArgumentException) {
    // Since `hours` is non-zero, `minutes` must be in the range of 0..59
}
try {
    UtcOffset(hours = -1, minutes = 30)
    fail("Expected IllegalArgumentException")
} catch (e: IllegalArgumentException) {
    // Since `hours` is negative, `minutes` must also be negative
} 
   //sampleEnd
}
actual fun UtcOffset(hours: Int? = null, minutes: Int? = null, seconds: Int? = null): UtcOffset(source)
actual fun UtcOffset(hours: Int? = null, minutes: Int? = null, seconds: Int? = null): UtcOffset(source)