does kotlinx-datetime have a way to get a date fro...
# kotlinx-datetime
n
does kotlinx-datetime have a way to get a date from the weeknumber ? i found a workaround using
java.util.Calendar
but i am not happy about it
Copy code
fun getMondayOfWeek(year: Int, week: Int): LocalDate {
    val cal = Calendar.getInstance()
    cal.set(Calendar.WEEK_OF_YEAR, week)
    cal.set(Calendar.YEAR, year)
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
    return cal.time.toInstant().toKotlinInstant().toLocalDateTime(systemTZ).date
}
is there a better way ?
i
You mean the week number of ISO week calendar?
n
yes, what i want is just to get the date of eg. monday of week 1 of a year all the rest can be solved with DateRange arithmetic
i
We do not have convenient way of working with ISO week calendar. If I recall correctly, the first week of year is the week with Thursday or, which is equivalent, the week with Jan 4. So in order to find the Monday of the first week, you can construct the date of (year, January, 4) and then scroll it to Monday:
date.plusDays(-date.dayOfWeek.ordinal)
o
That's correct, its ISO 8601 Note that some folks use a different week numbering system where week 1 is the week containing January 1.