Skip to content

Commit

Permalink
fix: add timezoneOffset to algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
zotovy committed Mar 27, 2022
1 parent 0a0e5af commit 1e4379f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

14 changes: 12 additions & 2 deletions library/src/main/java/dev/zotov/phototime/solarized/Algorithm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package dev.zotov.phototime.solarized

import androidx.annotation.FloatRange
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.temporal.TemporalUnit
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.math.*

/**
Expand Down Expand Up @@ -62,7 +66,8 @@ internal fun algorithm(
val zenith = -1 * twilight.degrees + 90

// local hour angle
val cosH = (cos(zenith.radians) - (sinDec * sin(latitude.radians))) / (cosDec * cos(latitude.radians))
val cosH =
(cos(zenith.radians) - (sinDec * sin(latitude.radians))) / (cosDec * cos(latitude.radians))

// no transition
if (cosH > 1 || cosH < -1) return null
Expand All @@ -86,7 +91,12 @@ internal fun algorithm(
else -> date
}

return setDate.withHour(hour).withMinute(minute).withSecond(second)
val timezoneOffset = TimeUnit.HOURS.convert(
TimeZone.getDefault().rawOffset.toLong(),
TimeUnit.MILLISECONDS
)

return setDate.withHour(hour).withMinute(minute).withSecond(second).plusHours(timezoneOffset)
}


Expand Down

0 comments on commit 1e4379f

Please sign in to comment.