parse

Parses an ISO 8601 week date string as a LocalIsoWeekDate.

Examples of week dates in the ISO 8601 format:

  • 2004-W53-6, the date 2005-01-01, Saturday

  • 2004-W53-7, the date 2005-01-02, Sunday

  • 2005-W52-6, the date 2005-12-31, Saturday

  • 2005-W52-7, the date 2006-01-01, Sunday

  • 2006-W01-1, the date 2006-01-02, Monday

  • 2009-W01-2, the date 2008-12-30, Tuesday

  • +12345-W05-2

  • -0015-W01-2

See ISO-8601-1:2019, 5.2.4.1b), using the "expanded calendar year" extension from 5.2.4.3a), generalized to any number of digits in the year for years that fit in an Int.

See also

for the dual operation: obtaining a string from a LocalIsoWeekDate.

for a version of this function that returns null on faulty input.

Throws

if the text cannot be parsed or the boundaries of LocalIsoWeekDate are exceeded.

Samples

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

fun main() { 
   //sampleStart 
   // Constructing a LocalIsoWeekDate from a string
check(LocalDate(2005, 1, 2) == LocalIsoWeekDate.parse("2004-W53-7").toLocalDate())
check(LocalDate(2008, 12, 29) == LocalIsoWeekDate.parse("2009-W01-1").toLocalDate()) 
   //sampleEnd
}