sortedWith

data class CustomDate(
    val year: Int,
    val month: Int,
    val day: Int
)

fun main() {
    var custumDates = listOf(
        CustomDate(2023, 1, 1),
        CustomDate(2023, 1, 2),
        CustomDate(2023, 2, 1),
        CustomDate(2022, 1, 1),
        CustomDate(2022, 1, 2),
        CustomDate(2022, 2, 1)
    )
        .shuffled()
        .sortedWith(
            compareBy<CustomDate> { it.year }
                .thenBy { it.month }
                .thenBy { it.day }
        )
    for (customDate in custumDates) {
        println(customDate.toString())
    }
}