-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: introduce TimeSpan class and avoid issue drawing background.
- Loading branch information
1 parent
57522b1
commit 47caba5
Showing
9 changed files
with
127 additions
and
45 deletions.
There are no files selected for viewing
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
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
27 changes: 27 additions & 0 deletions
27
library/src/main/java/de/tobiasschuerg/weekview/util/TimeSpan.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.tobiasschuerg.weekview.util | ||
|
||
import org.threeten.bp.Duration | ||
import org.threeten.bp.LocalTime | ||
|
||
/** | ||
* Holds a duration of time. | ||
*/ | ||
data class TimeSpan( | ||
val start: LocalTime, | ||
val endExclusive: LocalTime | ||
) { | ||
|
||
init { | ||
require(start.isBefore(endExclusive)) { | ||
"Start time $start must be before end time $endExclusive!" | ||
} | ||
} | ||
|
||
val duration: Duration by lazy { Duration.between(start, endExclusive) } | ||
|
||
companion object { | ||
fun of(start: LocalTime, duration: Duration): TimeSpan { | ||
return TimeSpan(start, start.plus(duration)) | ||
} | ||
} | ||
} |
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
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
30 changes: 30 additions & 0 deletions
30
library/src/test/java/de/tobiasschuerg/weekview/util/TimeSpanTest.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.tobiasschuerg.weekview.util | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.threeten.bp.Duration | ||
import org.threeten.bp.LocalTime | ||
|
||
/** | ||
* Created by Tobias Schrg on 11.02.2022. | ||
*/ | ||
class TimeSpanTest { | ||
|
||
@Test | ||
fun testDuration() { | ||
val timeSpan = TimeSpan( | ||
start = LocalTime.of(10, 15), | ||
endExclusive = LocalTime.of(10, 45) | ||
) | ||
assertEquals(Duration.ofMinutes(30), timeSpan.duration) | ||
} | ||
|
||
@Test | ||
fun testDuration2() { | ||
val timeSpan = TimeSpan.of( | ||
start = LocalTime.of(10, 15), | ||
duration = Duration.ofMinutes(30) | ||
) | ||
assertEquals(Duration.ofMinutes(30), timeSpan.duration) | ||
} | ||
} |