Skip to content

Instantly share code, notes, and snippets.

@h0tk3y
Created July 11, 2016 14:13
Show Gist options
  • Select an option

  • Save h0tk3y/adee632e5d21a566e52ba3fdd34a548c to your computer and use it in GitHub Desktop.

Select an option

Save h0tk3y/adee632e5d21a566e52ba3fdd34a548c to your computer and use it in GitHub Desktop.
import java.util.*
import kotlin.reflect.KMutableProperty1
fun <T> KMutableProperty1<T, Date>.addDays(receiver: T, nrOfDays: Int) {
val cal = Calendar.getInstance()
cal.time = this.get(receiver)
cal.add(Calendar.DAY_OF_YEAR, nrOfDays)
this.set(receiver, cal.time)
}
class C(var date: Date)
fun main(args: Array<String>) {
val c = C(Date(0))
C::date.addDays(c, 123)
println(c.date)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment