Skip to content

Commit

Permalink
feat: made firstLight and lastLight nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
zotovy committed May 8, 2022
1 parent 28d0619 commit e378e50
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
6 changes: 0 additions & 6 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import kotlin.math.*
internal fun algorithm(
time: DateTime,
date: LocalDateTime,
@FloatRange(from = 0.0, to = 90.0) latitude: Double,
@FloatRange(from = 0.0, to = 180.0) longitude: Double,
@FloatRange(from = -90.0, to = 90.0) latitude: Double,
@FloatRange(from = -180.0, to = 180.0) longitude: Double,
twilight: Twilight,
timeZone: TimeZone
): LocalDateTime? {
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/dev/zotov/phototime/solarized/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ sealed class SunPhase {
* List, containing all sun phases during daytime
*/
data class SunPhaseList(
val firstLight: SunPhase.FirstLight,
val firstLight: SunPhase.FirstLight?,
val morningBlueHour: SunPhase.BlueHour,
val sunrise: SunPhase.Sunrise,
val morningGoldenHour: SunPhase.GoldenHour,
val day: SunPhase.Day,
val eveningGoldenHour: SunPhase.GoldenHour,
val sunset: SunPhase.Sunset,
val eveningBlueHour: SunPhase.BlueHour,
val lastLight: SunPhase.LastLight,
val lastLight: SunPhase.LastLight?,
)

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import java.util.*
* @param timeZone of LocalDateTime
*/
class Solarized(
@FloatRange(from = 0.0, to = 90.0) val latitude: Double,
@FloatRange(from = 0.0, to = 180.0) val longitude: Double,
@FloatRange(from = -90.0, to = 90.0) val latitude: Double,
@FloatRange(from = -180.0, to = 180.0) val longitude: Double,
val date: LocalDateTime,
val timeZone: TimeZone = TimeZone.getDefault()
) {
Expand Down Expand Up @@ -81,7 +81,7 @@ class Solarized(
) ?: return null

return SunPhaseList(
firstLight = firstLight ?: return null,
firstLight = firstLight,
morningBlueHour = SunPhase.BlueHour(
start = blueHourMorningStartDate,
end = blueHourMorningEndDate
Expand All @@ -104,7 +104,7 @@ class Solarized(
start = goldenHourEveningEndDate,
end = blueHourEveningEndDate,
),
lastLight = lastLight ?: return null,
lastLight = lastLight,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package dev.zotov.phototime.solarized

import org.junit.Assert
import org.junit.Test
import java.time.Instant
import java.time.ZoneOffset
import java.util.*

class PermUnitTest {

private val date = Instant.ofEpochSecond(1651679484).atZone(ZoneOffset.UTC).toLocalDateTime()
private val latitude = 58.000000
private val longitude = 56.316666
private val timezone = TimeZone.getTimeZone("Asia/Yekaterinburg")
private val solarized = Solarized(latitude, longitude, date, timezone)

@Test
fun `Morning blur hour`() {
fun `Morning blue hour`() {
solarized.blueHour.morning!!.assertTime("04:06-04:46")
}

Expand Down Expand Up @@ -47,4 +47,24 @@ class PermUnitTest {
fun `Evening blue hour`() {
solarized.blueHour.evening!!.assertTime("21:37-22:18")
}
}

class PermUnitTest2 {
private val date = Instant.ofEpochSecond(1652011132).atZone(ZoneOffset.UTC).toLocalDateTime()
private val latitude = 58.0368
private val longitude = 56.2632
private val timezone = TimeZone.getTimeZone("Asia/Yekaterinburg")
private val solarized = Solarized(latitude, longitude, date, timezone)

@Test
fun `list is not null`() {
Assert.assertNotNull(solarized.blueHour.morning)
Assert.assertNotNull(solarized.goldenHour.morning)
Assert.assertNotNull(solarized.sunrise)
Assert.assertNotNull(solarized.day)
Assert.assertNotNull(solarized.goldenHour.evening)
Assert.assertNotNull(solarized.blueHour.evening)
Assert.assertNotNull(solarized.sunset)
Assert.assertNotNull(solarized.list)
}
}

0 comments on commit e378e50

Please sign in to comment.