Fix wrong month numeration
authorVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Fri, 12 Jan 2018 12:50:26 +0000 (15:50 +0300)
committerVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Fri, 12 Jan 2018 14:13:50 +0000 (17:13 +0300)
plugins/stats-collector/src/com/intellij/stats/personalization/impl/DayImpl.kt
plugins/stats-collector/test/com/intellij/stats/personalization/AggregatedFactorTest.kt

index 315710fff28f577ea2916263d7cb35f98db80cd4..89ffc49dd19bdcb471eb278168e9a4ae0fd02e32 100644 (file)
@@ -44,7 +44,9 @@ class DayImpl(date: Date) : Day {
         val calendar = Calendar.getInstance()
         calendar.time = date
         dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)
         val calendar = Calendar.getInstance()
         calendar.time = date
         dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)
-        month = calendar.get(Calendar.MONTH)
+        // a month is a zero-based property for some reason
+        // see details: https://stackoverflow.com/questions/344380/why-is-january-month-0-in-java-calendar
+        month = calendar.get(Calendar.MONTH) + 1
         year = calendar.get(Calendar.YEAR)
     }
 
         year = calendar.get(Calendar.YEAR)
     }
 
index 07d0fddc25a21d338a80c0f356c524ed8b1083d1..8248bfc51f7f72fc81fe3bb9f7f88501ec8990c1 100644 (file)
@@ -11,14 +11,14 @@ import java.util.*
  */
 class AggregatedFactorTest : UsefulTestCase() {
     private companion object {
  */
 class AggregatedFactorTest : UsefulTestCase() {
     private companion object {
-        val DATE_1 = DateUtil.byDate(Calendar.Builder().setDate(2010, 1, 1).build().time)
+        val DATE_1 = DateUtil.byDate(Calendar.Builder().setDate(2010, 0, 1).build().time)
         val DATE_2 = DATE_1.update(1)
         val DATE_3 = DATE_1.update(2)
         val DATE_4 = DATE_1.update(3)
 
         fun Day.update(count: Int): Day {
             return Calendar.getInstance().let {
         val DATE_2 = DATE_1.update(1)
         val DATE_3 = DATE_1.update(2)
         val DATE_4 = DATE_1.update(3)
 
         fun Day.update(count: Int): Day {
             return Calendar.getInstance().let {
-                it.set(year, month, dayOfMonth)
+                it.set(year, month - 1, dayOfMonth)
                 it.add(Calendar.DATE, count)
                 DateUtil.byDate(it.time)
             }
                 it.add(Calendar.DATE, count)
                 DateUtil.byDate(it.time)
             }