Description
Implement the function
MyDate.rangeTo(). This allows you to create a range of dates using the following syntax:
下記の構文を使って日付の範囲を作成できるように、関数
MyDate.rangeTo()を実装してください。
MyDate(2015, 5, 11)..MyDate(2015, 5, 12)
Note that now the class
DateRangeimplements the standardClosedRangeinterface and inheritscontainsmethod implementation.
DateRangeは、標準ライブラリのClosedRangeインターフェースを実装し、containsメソッドの実装を継承していることに注意してください。
Code
operator fun MyDate.rangeTo(other: MyDate) = DateRange(this, other)
class DateRange(override val start: MyDate, override val endInclusive: MyDate): ClosedRange<MyDate>
fun checkInRange(date: MyDate, first: MyDate, last: MyDate): Boolean {
return date in first..last
}