Kotlinチュートリアル(Range to)

Run Settings
LanguageKotlin
Language Version
Run Command
/** * You can edit, run, and share this code. * play.kotlinlang.org */// data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate> { override fun compareTo(other: MyDate) = when { year != other.year -> year - other.year month != other.month -> month - other.month else -> dayOfMonth - other.dayOfMonth } } 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 } fun main(args : Array<String>){ //-----checkInRangeを使ってみる //今日(2019年8月20日) var today = MyDate(2019,8,31) //去年の始めと終わり(戌年) val inu_FirstDay = MyDate(2018,1,1) val inu_LastDay = MyDate(2018,12,31) //今年の初めと終わり(亥年) val inosisi_FirstDay = MyDate(2019,1,1) val inosisi_LastDay = MyDate(2019,12,31) println("今日は戌年か? ${checkInRange(date=today,first=inu_FirstDay,last=inu_LastDay)}") println("今日は亥年か? ${checkInRange(date=today,first=inosisi_FirstDay,last=inosisi_LastDay)}") //-----checkInRangeを使ってみる }
Editor Settings
Theme
Key bindings
Full width
Lines