forked from github/wulkanowy-mirror
Expand exam sync date range to next month (#960)
This commit is contained in:
parent
47150364d8
commit
5d8fb376ab
@ -2,9 +2,9 @@ package io.github.wulkanowy.data.repositories.exam
|
|||||||
|
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.utils.monday
|
import io.github.wulkanowy.utils.endExamsDay
|
||||||
import io.github.wulkanowy.utils.networkBoundResource
|
import io.github.wulkanowy.utils.networkBoundResource
|
||||||
import io.github.wulkanowy.utils.sunday
|
import io.github.wulkanowy.utils.startExamsDay
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -18,8 +18,8 @@ class ExamRepository @Inject constructor(
|
|||||||
|
|
||||||
fun getExams(student: Student, semester: Semester, start: LocalDate, end: LocalDate, forceRefresh: Boolean) = networkBoundResource(
|
fun getExams(student: Student, semester: Semester, start: LocalDate, end: LocalDate, forceRefresh: Boolean) = networkBoundResource(
|
||||||
shouldFetch = { it.isEmpty() || forceRefresh },
|
shouldFetch = { it.isEmpty() || forceRefresh },
|
||||||
query = { local.getExams(semester, start.monday, end.sunday) },
|
query = { local.getExams(semester, start.startExamsDay, start.endExamsDay) },
|
||||||
fetch = { remote.getExams(student, semester, start.monday, end.sunday) },
|
fetch = { remote.getExams(student, semester, start.startExamsDay, start.endExamsDay) },
|
||||||
saveFetchResult = { old, new ->
|
saveFetchResult = { old, new ->
|
||||||
local.deleteExams(old uniqueSubtract new)
|
local.deleteExams(old uniqueSubtract new)
|
||||||
local.saveExams(new uniqueSubtract old)
|
local.saveExams(new uniqueSubtract old)
|
||||||
|
@ -3,8 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.exam.ExamRepository
|
import io.github.wulkanowy.data.repositories.exam.ExamRepository
|
||||||
import io.github.wulkanowy.utils.monday
|
|
||||||
import io.github.wulkanowy.utils.sunday
|
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
import java.time.LocalDate.now
|
import java.time.LocalDate.now
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -12,6 +10,6 @@ import javax.inject.Inject
|
|||||||
class ExamWork @Inject constructor(private val examRepository: ExamRepository) : Work {
|
class ExamWork @Inject constructor(private val examRepository: ExamRepository) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester) {
|
||||||
examRepository.getExams(student, semester, now().monday, now().sunday, true).waitForResult()
|
examRepository.getExams(student, semester, now(), now(), true).waitForResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,7 @@ import java.time.Month
|
|||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
import java.time.format.DateTimeFormatter.ofPattern
|
import java.time.format.DateTimeFormatter.ofPattern
|
||||||
import java.time.format.TextStyle.FULL_STANDALONE
|
import java.time.format.TextStyle.FULL
|
||||||
import java.time.format.TextStyle.*
|
|
||||||
import java.time.temporal.TemporalAdjusters.firstInMonth
|
import java.time.temporal.TemporalAdjusters.firstInMonth
|
||||||
import java.time.temporal.TemporalAdjusters.next
|
import java.time.temporal.TemporalAdjusters.next
|
||||||
import java.time.temporal.TemporalAdjusters.previous
|
import java.time.temporal.TemporalAdjusters.previous
|
||||||
@ -78,6 +77,12 @@ inline val LocalDate.nextOrSameSchoolDay: LocalDate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline val LocalDate.startExamsDay: LocalDate
|
||||||
|
get() = nextOrSameSchoolDay.monday
|
||||||
|
|
||||||
|
inline val LocalDate.endExamsDay: LocalDate
|
||||||
|
get() = nextOrSameSchoolDay.monday.plusWeeks(4).minusDays(1)
|
||||||
|
|
||||||
inline val LocalDate.previousOrSameSchoolDay: LocalDate
|
inline val LocalDate.previousOrSameSchoolDay: LocalDate
|
||||||
get() {
|
get() {
|
||||||
return when (dayOfWeek) {
|
return when (dayOfWeek) {
|
||||||
|
@ -171,4 +171,42 @@ class TimeExtensionTest {
|
|||||||
assertEquals(of(2019, 5, 1), of(2019, 5, 1).getLastSchoolDayIfHoliday(2018))
|
assertEquals(of(2019, 5, 1), of(2019, 5, 1).getLastSchoolDayIfHoliday(2018))
|
||||||
assertEquals(of(2018, 5, 1), of(2019, 5, 1).getLastSchoolDayIfHoliday(2017))
|
assertEquals(of(2018, 5, 1), of(2019, 5, 1).getLastSchoolDayIfHoliday(2017))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getExamsCutOffDates() {
|
||||||
|
with(of(2020, 9, 13)) {
|
||||||
|
assertEquals(of(2020, 9, 14), startExamsDay)
|
||||||
|
assertEquals(of(2020, 10, 11), endExamsDay)
|
||||||
|
}
|
||||||
|
|
||||||
|
with(of(2020, 9, 14)) {
|
||||||
|
assertEquals(of(2020, 9, 14), startExamsDay)
|
||||||
|
assertEquals(of(2020, 10, 11), endExamsDay)
|
||||||
|
}
|
||||||
|
|
||||||
|
with(of(2020, 9, 15)) {
|
||||||
|
assertEquals(of(2020, 9, 14), startExamsDay)
|
||||||
|
assertEquals(of(2020, 10, 11), endExamsDay)
|
||||||
|
}
|
||||||
|
|
||||||
|
with(of(2020, 9, 16)) {
|
||||||
|
assertEquals(of(2020, 9, 14), startExamsDay)
|
||||||
|
assertEquals(of(2020, 10, 11), endExamsDay)
|
||||||
|
}
|
||||||
|
|
||||||
|
with(of(2020, 9, 17)) {
|
||||||
|
assertEquals(of(2020, 9, 14), startExamsDay)
|
||||||
|
assertEquals(of(2020, 10, 11), endExamsDay)
|
||||||
|
}
|
||||||
|
|
||||||
|
with(of(2020, 9, 18)) {
|
||||||
|
assertEquals(of(2020, 9, 14), startExamsDay)
|
||||||
|
assertEquals(of(2020, 10, 11), endExamsDay)
|
||||||
|
}
|
||||||
|
|
||||||
|
with(of(2020, 9, 19)) {
|
||||||
|
assertEquals(of(2020, 9, 21), startExamsDay)
|
||||||
|
assertEquals(of(2020, 10, 18), endExamsDay)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user