Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #41 from Sage-Bionetworks/session-window-updates
Browse files Browse the repository at this point in the history
Updates to ScheduledSessionWindow
  • Loading branch information
nategbrown9 authored Jul 8, 2021
2 parents 0b1f95a + 72281e9 commit 69c2925
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ class ScheduleTimelineRepo(internal val adherenceRecordRepo: AdherenceRecordRepo
sessionInfo = session,
assessments = assessments,
event = event,
isExpired = isExpired,
isCompleted = isCompleted,
startDateTime = startDateTime,
endDateTime = endDateTime,
notifications = if (notifications.isNullOrEmpty()) null else notifications
Expand Down Expand Up @@ -449,8 +447,6 @@ data class ScheduledSessionWindow (
val event: StudyActivityEvent,
val startDateTime: LocalDateTime,
val endDateTime: LocalDateTime,
val isExpired: Boolean,
val isCompleted: Boolean,
val assessments: List<ScheduledAssessmentReference>,
val sessionInfo: SessionInfo,
val notifications: List<ScheduledNotification>?,
Expand All @@ -460,6 +456,22 @@ data class ScheduledSessionWindow (
val hasStartTimeOfDay = startDateTime.hour == 0 && startDateTime.minute == 0
val hasEndTimeOfDay = scheduledSession.expiration.let { it.hours > 0 || it.minutes > 0 }
val persistent = scheduledSession.persistent
val isCompleted = assessments.all { it.isCompleted }

fun isAvailableNow(now: Instant = Clock.System.now()): Boolean {
val timeZone = TimeZone.currentSystemDefault()
return startDateTime.toInstant(timeZone) <= now && now < endDateTime.toInstant(timeZone)
}

fun isInFuture(now: Instant = Clock.System.now()): Boolean {
val timeZone = TimeZone.currentSystemDefault()
return startDateTime.toInstant(timeZone) > now
}

fun isInPast(now: Instant = Clock.System.now()): Boolean {
val timeZone = TimeZone.currentSystemDefault()
return endDateTime.toInstant(timeZone) < now
}
}

data class ScheduledAssessmentReference (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,17 @@ class ScheduleTimelineRepoTest: BaseTest() {
val session2 = sessionList[1]
assertEquals("Daily Sessions", session2.sessionInfo.label)
assertEquals("XlZ3SrLpmEQ2E8PuUUcs7g", session2.instanceGuid)
assertFalse(session2.isInPast(getTodayInstant()))
assertTrue(session2.isAvailableNow(getTodayInstant()))
assertFalse(session2.isInFuture(getTodayInstant()))

//Third session will be starting next hour
val session3 = sessionList[2]
assertEquals("Daily Sessions", session3.sessionInfo.label)
assertEquals("-B_yTKp8eTGK7NY_qJ0UTA", session3.instanceGuid)
assertFalse(session3.isInPast(getTodayInstant()))
assertFalse(session3.isAvailableNow(getTodayInstant()))
assertTrue(session3.isInFuture(getTodayInstant()))
}
}

Expand Down

0 comments on commit 69c2925

Please sign in to comment.