forked from EventFahrplan/EventFahrplan
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request EventFahrplan#605 from EventFahrplan/moment-class-…
…adoption Refactor ConferenceTimeFrame to use closed range internally.
- Loading branch information
Showing
3 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
32 changes: 23 additions & 9 deletions
32
app/src/main/java/nerd/tuxmobil/fahrplan/congress/utils/ConferenceTimeFrame.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,49 @@ | ||
package nerd.tuxmobil.fahrplan.congress.utils | ||
|
||
import info.metadude.android.eventfahrplan.commons.temporal.Moment | ||
|
||
import nerd.tuxmobil.fahrplan.congress.alarms.AlarmUpdater | ||
import nerd.tuxmobil.fahrplan.congress.schedule.Conference | ||
|
||
/** | ||
* Represents the time frame of a conference which is taken into account by the [AlarmUpdater] | ||
* to calculate if and when alarms should fire. | ||
* | ||
* This class should not be used for other purposes. | ||
* It is not a replacement for the [Conference] class. | ||
*/ | ||
// TODO Merge with Conference class? | ||
class ConferenceTimeFrame( | ||
|
||
val firstDayStartTime: Moment, | ||
private val lastDayEndTime: Moment | ||
firstDayStartTime: Moment, | ||
lastDayEndTime: Moment | ||
|
||
) { | ||
|
||
private val timeFrame = firstDayStartTime..lastDayEndTime | ||
|
||
init { | ||
check(isValid) { "Invalid conference time frame: $this" } | ||
} | ||
|
||
val firstDayStartTime: Moment | ||
get() = timeFrame.start | ||
|
||
val isValid: Boolean | ||
get() = firstDayStartTime.isBefore(lastDayEndTime) | ||
get() = timeFrame.start.isBefore(timeFrame.endInclusive) | ||
|
||
operator fun contains(moment: Moment) = | ||
startsAtOrBefore(moment) && lastDayEndTime.isAfter(moment) | ||
startsAtOrBefore(moment) && timeFrame.endInclusive.isAfter(moment) | ||
|
||
fun endsAtOrBefore(moment: Moment) = | ||
lastDayEndTime.isSimultaneousWith(moment) || lastDayEndTime.isBefore(moment) | ||
timeFrame.endInclusive.isSimultaneousWith(moment) || timeFrame.endInclusive.isBefore(moment) | ||
|
||
fun startsAfter(moment: Moment) = | ||
firstDayStartTime.isAfter(moment) | ||
timeFrame.start.isAfter(moment) | ||
|
||
fun startsAtOrBefore(moment: Moment) = | ||
firstDayStartTime.isSimultaneousWith(moment) || firstDayStartTime.isBefore(moment) | ||
timeFrame.start.isSimultaneousWith(moment) || timeFrame.start.isBefore(moment) | ||
|
||
override fun toString() = | ||
"firstDayStartTime = $firstDayStartTime, lastDayEndTime = $lastDayEndTime" | ||
timeFrame.toString() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters