properly handle daylight savings
This commit is contained in:
parent
b3873e726c
commit
b6e0d8381f
|
@ -83,8 +83,13 @@ class TimeZonesAdapter(activity: SimpleActivity, var timeZones: ArrayList<MyTime
|
|||
}
|
||||
|
||||
private fun setupView(view: View, timeZone: MyTimeZone) {
|
||||
val calendar = Calendar.getInstance(TimeZone.getTimeZone(timeZone.zoneName))
|
||||
val offset = calendar.timeZone.rawOffset
|
||||
val currTimeZone = TimeZone.getTimeZone(timeZone.zoneName)
|
||||
val calendar = Calendar.getInstance(currTimeZone)
|
||||
var offset = calendar.timeZone.rawOffset
|
||||
val isDaylightSavingActive = currTimeZone.inDaylightTime(Date())
|
||||
if (isDaylightSavingActive) {
|
||||
offset += currTimeZone.dstSavings
|
||||
}
|
||||
val passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt()
|
||||
val formattedTime = activity.getFormattedTime(passedSeconds, false, false)
|
||||
val formattedDate = activity.getFormattedDate(calendar)
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.simplemobiletools.clock.extensions.config
|
|||
import com.simplemobiletools.clock.extensions.getAllTimeZonesModified
|
||||
import com.simplemobiletools.clock.extensions.getFormattedDate
|
||||
import com.simplemobiletools.clock.extensions.getFormattedTime
|
||||
import com.simplemobiletools.clock.helpers.getPassedSeconds
|
||||
import com.simplemobiletools.clock.models.MyTimeZone
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
|
@ -62,8 +63,7 @@ class ClockFragment : Fragment() {
|
|||
|
||||
private fun setupDateTime() {
|
||||
calendar = Calendar.getInstance()
|
||||
val offset = calendar.timeZone.rawOffset
|
||||
passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt()
|
||||
passedSeconds = getPassedSeconds()
|
||||
displayOtherTimeZones = context!!.config.displayOtherTimeZones
|
||||
updateCurrentTime()
|
||||
updateDate()
|
||||
|
|
|
@ -48,7 +48,11 @@ fun getMSTillNextMinute(): Long {
|
|||
|
||||
fun getPassedSeconds(): Int {
|
||||
val calendar = Calendar.getInstance()
|
||||
val offset = calendar.timeZone.rawOffset
|
||||
val isDaylightSavingActive = TimeZone.getDefault().inDaylightTime(Date())
|
||||
var offset = calendar.timeZone.rawOffset
|
||||
if (isDaylightSavingActive) {
|
||||
offset += TimeZone.getDefault().dstSavings
|
||||
}
|
||||
return ((calendar.timeInMillis + offset) / 1000).toInt()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue