From e378e50876c8de444a994a89cef0acdd58579890 Mon Sep 17 00:00:00 2001 From: Yaroslav Zotov <35657233+zotovy@users.noreply.github.com> Date: Sun, 8 May 2022 17:43:33 +0500 Subject: [PATCH] feat: made `firstLight` and `lastLight` nullable --- .idea/vcs.xml | 6 ----- .../zotov/phototime/solarized/Algorithm.kt | 4 ++-- .../dev/zotov/phototime/solarized/Models.kt | 4 ++-- .../zotov/phototime/solarized/Solarized.kt | 8 +++---- .../zotov/phototime/solarized/PermUnitTest.kt | 24 +++++++++++++++++-- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 4c6280e..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,11 +1,5 @@ - - - - - - diff --git a/library/src/main/java/dev/zotov/phototime/solarized/Algorithm.kt b/library/src/main/java/dev/zotov/phototime/solarized/Algorithm.kt index fa1ac02..1b8618d 100644 --- a/library/src/main/java/dev/zotov/phototime/solarized/Algorithm.kt +++ b/library/src/main/java/dev/zotov/phototime/solarized/Algorithm.kt @@ -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? { diff --git a/library/src/main/java/dev/zotov/phototime/solarized/Models.kt b/library/src/main/java/dev/zotov/phototime/solarized/Models.kt index 1193348..b431fd8 100644 --- a/library/src/main/java/dev/zotov/phototime/solarized/Models.kt +++ b/library/src/main/java/dev/zotov/phototime/solarized/Models.kt @@ -53,7 +53,7 @@ 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, @@ -61,6 +61,6 @@ data class SunPhaseList( val eveningGoldenHour: SunPhase.GoldenHour, val sunset: SunPhase.Sunset, val eveningBlueHour: SunPhase.BlueHour, - val lastLight: SunPhase.LastLight, + val lastLight: SunPhase.LastLight?, ) diff --git a/library/src/main/java/dev/zotov/phototime/solarized/Solarized.kt b/library/src/main/java/dev/zotov/phototime/solarized/Solarized.kt index 1c271b7..a0b2c45 100644 --- a/library/src/main/java/dev/zotov/phototime/solarized/Solarized.kt +++ b/library/src/main/java/dev/zotov/phototime/solarized/Solarized.kt @@ -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() ) { @@ -81,7 +81,7 @@ class Solarized( ) ?: return null return SunPhaseList( - firstLight = firstLight ?: return null, + firstLight = firstLight, morningBlueHour = SunPhase.BlueHour( start = blueHourMorningStartDate, end = blueHourMorningEndDate @@ -104,7 +104,7 @@ class Solarized( start = goldenHourEveningEndDate, end = blueHourEveningEndDate, ), - lastLight = lastLight ?: return null, + lastLight = lastLight, ) } diff --git a/library/src/test/java/dev/zotov/phototime/solarized/PermUnitTest.kt b/library/src/test/java/dev/zotov/phototime/solarized/PermUnitTest.kt index 5f087f3..731f991 100644 --- a/library/src/test/java/dev/zotov/phototime/solarized/PermUnitTest.kt +++ b/library/src/test/java/dev/zotov/phototime/solarized/PermUnitTest.kt @@ -1,12 +1,12 @@ 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 @@ -14,7 +14,7 @@ class PermUnitTest { 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") } @@ -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) + } } \ No newline at end of file