setOffset

fun setOffset(utcOffset: UtcOffset)(source)

Writes the contents of the specified utcOffset to this DateTimeComponents. The utcOffset is written to the offsetHours, offsetMinutesOfHour, offsetSecondsOfMinute, and offsetIsNegative fields.

If any of the fields are already set, they will be overwritten.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Formatting and parsing a UTC offset in complex scenarios
val format = DateTimeComponents.Format { offset(UtcOffset.Formats.ISO) }
val formattedOffset = format.format {
    setOffset(UtcOffset(-3, -30, -15))
    check(offsetHours == 3)
    check(offsetMinutesOfHour == 30)
    check(offsetSecondsOfMinute == 15)
    check(offsetIsNegative == true)
}
check(formattedOffset == "-03:30:15")
val parsedOffset = format.parse("-03:30:15")
check(parsedOffset.toUtcOffset() == UtcOffset(-3, -30, -15))
check(parsedOffset.offsetHours == 3)
check(parsedOffset.offsetMinutesOfHour == 30)
check(parsedOffset.offsetSecondsOfMinute == 15)
check(parsedOffset.offsetIsNegative == true) 
   //sampleEnd
}