Is there a shorthand for this? ```fun Date.toCalen...
# announcements
i
Is there a shorthand for this?
Copy code
fun Date.toCalendar(): Calendar {
    val calendar = Calendar.getInstance()
    calendar.time = this
    return calendar
}
t
Something like this might work:
Copy code
fun Date.toCalendar() = 
    Calendar.getInstance().apply {
        time = this@toCalendar
    }
👍 1
c
use
LocalDateTime
instead?
💯 3
i
@codeslubber that's Java 8, right? Can't use it on Android
@todd.ginsberg doesn't this create endless recursion?
t
No, you are using apply to scope setting
time
and
this@toCalendar
sets it to the
Date
that the
toCalendar
function is being called on.
I just ran it and it works.
c
@iex think you can…