1 package com.intellij.stats.personalization.impl
3 import com.intellij.stats.personalization.Day
4 import java.text.ParsePosition
5 import java.text.SimpleDateFormat
9 * @author Vitaliy.Bibaev
11 class DayImpl(date: Date) : Day {
12 override val dayOfMonth: Int
13 override val month: Int
14 override val year: Int
17 private val DATE_FORMAT = SimpleDateFormat("dd-MM-yyyy")
19 fun fromString(str: String): Day? {
20 val position = ParsePosition(0)
21 val date = DATE_FORMAT.parse(str, position)
22 if (position.index == 0) return null
28 val calendar = Calendar.getInstance()
30 dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)
31 month = calendar.get(Calendar.MONTH)
32 year = calendar.get(Calendar.YEAR)
35 override fun compareTo(other: Day): Int {
36 if (year == other.year) {
37 if (month == other.month) {
38 return dayOfMonth.compareTo(other.dayOfMonth)
40 return month.compareTo(other.month)
42 return year.compareTo(other.year)
45 override fun hashCode(): Int {
46 return Objects.hash(year, month, dayOfMonth)
49 override fun equals(other: Any?): Boolean {
50 if (other != null && other is Day) return compareTo(other) == 0
54 override fun toString(): String {
55 return "$dayOfMonth-$month-$year"