Change month in attendance summary to threetenbp Month enum

This commit is contained in:
Mikołaj Pich 2018-12-06 23:00:04 +01:00
parent ba17abc70e
commit 6a73b0ed37
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
4 changed files with 30 additions and 13 deletions

View file

@ -1,7 +1,9 @@
package io.github.wulkanowy.api.attendance
import org.threeten.bp.Month
data class AttendanceSummary(
val month: String,
val month: Month,
val presence: Int,
val absence: Int,
val absenceExcused: Int,

View file

@ -19,13 +19,8 @@ import io.github.wulkanowy.api.student.StudentInfo
import io.github.wulkanowy.api.timetable.Timetable
import io.github.wulkanowy.api.timetable.TimetableParser
import io.reactivex.Single
import org.threeten.bp.DayOfWeek
import org.threeten.bp.Instant
import org.threeten.bp.LocalDate
import org.threeten.bp.ZoneId
import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.temporal.TemporalAdjusters
import java.text.SimpleDateFormat
import org.threeten.bp.Month
import java.util.*
class StudentAndParentRepository(private val api: StudentAndParentService) {
@ -56,7 +51,7 @@ class StudentAndParentRepository(private val api: StudentAndParentService) {
return api.getAttendanceSummary(subjectId).map { res ->
res.months.mapIndexedNotNull { i, month ->
if (res.summaryRows.all { it.value[i].isBlank() }) return@mapIndexedNotNull null
AttendanceSummary(month,
AttendanceSummary(romanToMonthEnum(month),
res.summaryRows[0].value[i].toIntOrNull() ?: 0,
res.summaryRows[1].value[i].toIntOrNull() ?: 0,
res.summaryRows[2].value[i].toIntOrNull() ?: 0,
@ -220,4 +215,22 @@ class StudentAndParentRepository(private val api: StudentAndParentService) {
val utcOffset = c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)
return ((c.timeInMillis + utcOffset) * 10000 + 621355968000000000L).toString()
}
private fun romanToMonthEnum(romanMonth: String): Month {
return Month.of(when (romanMonth) {
"I" -> 1
"II" -> 2
"III" -> 3
"IV" -> 4
"V" -> 5
"VI" -> 6
"VII" -> 7
"VIII" -> 8
"IX" -> 9
"X" -> 10
"XI" -> 11
"XII" -> 12
else -> 0
})
}
}

View file

@ -28,6 +28,7 @@ import org.junit.Assert.*
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.threeten.bp.Month
@Ignore
class ApiRemoteTest : BaseTest() {
@ -165,7 +166,7 @@ class ApiRemoteTest : BaseTest() {
assertEquals(10, values.size)
values[0].run {
assertEquals("IX", month)
assertEquals(Month.SEPTEMBER, month)
assertEquals(32, presence)
assertEquals(1, absence)
assertEquals(2, absenceExcused)

View file

@ -3,6 +3,7 @@ package io.github.wulkanowy.api.attendance
import io.github.wulkanowy.api.BaseLocalTest
import org.junit.Assert.assertEquals
import org.junit.Test
import org.threeten.bp.Month
class AttendanceSummaryTest : BaseLocalTest() {
@ -28,10 +29,10 @@ class AttendanceSummaryTest : BaseLocalTest() {
@Test
fun getAttendanceSummary_month() {
assertEquals("IX", table[0].month)
assertEquals("X", table[1].month)
assertEquals("XI", table[2].month)
assertEquals("VI", table[9].month)
assertEquals(Month.SEPTEMBER, table[0].month)
assertEquals(Month.OCTOBER, table[1].month)
assertEquals(Month.NOVEMBER, table[2].month)
assertEquals(Month.JUNE, table[9].month)
}
@Test