Skip to content

Commit b81fab0

Browse files
committed
Comparison task solution
1 parent fd83492 commit b81fab0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Conventions/Comparison/src/Task.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
import java.util.*
2+
13
data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate> {
2-
/* TODO */
4+
override fun compareTo(other: MyDate): Int {
5+
val firstDate = Calendar.getInstance()
6+
firstDate.set(year, month, dayOfMonth)
7+
val secondDate = Calendar.getInstance()
8+
secondDate.set(other.year, other.month, other.dayOfMonth)
9+
return firstDate.compareTo(secondDate)
10+
}
311
}
412

513
fun compare(date1: MyDate, date2: MyDate) = date1 < date2

0 commit comments

Comments
 (0)