Potential confusion in this example



I’ve been doing the kotlin koans, which are great.

There is potential confusion in this example

date util

Particularly this method

When setting calling calendar.set(year, month, day), month is zero based java, but in MyDate it is not obvious that it is zero based or one based, so this could seem like it rolls over to the next month if the caller is unaware,

fun MyDate.addTimeIntervals(timeInterval: TimeInterval, number: Int): MyDate {
val c = Calendar.getInstance()
c.set(this.year, this.month, this.dayOfMonth)
when (timeInterval) {
TimeInterval.DAY -> c.add(Calendar.DAY_OF_MONTH, number)
TimeInterval.WEEK -> c.add(Calendar.WEEK_OF_MONTH, number)
TimeInterval.YEAR -> c.add(Calendar.YEAR, number)
return MyDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE))


First of all I’m surprised that they hadn’t just used LocalDate for that. It would be much simpler then.