joda -> java.time

This commit is contained in:
Milos Kozak 2023-12-06 18:09:42 +01:00
parent 05895b643c
commit bafdaa304d
2 changed files with 11 additions and 7 deletions

View file

@ -1,9 +1,11 @@
package app.aaps.plugins.constraints.versionChecker package app.aaps.plugins.constraints.versionChecker
import org.joda.time.LocalDate
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneId
class AllowedVersions { class AllowedVersions {
@ -38,7 +40,8 @@ class AllowedVersions {
fun endDateToMilliseconds(endDate: String): Long? { fun endDateToMilliseconds(endDate: String): Long? {
try { try {
val dateTime = LocalDate.parse(endDate) val dateTime = LocalDate.parse(endDate)
return dateTime.toDate().time val instant = dateTime.atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant()
return instant.toEpochMilli()
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
return null return null

View file

@ -1,11 +1,12 @@
package app.aaps.plugins.constraints.versionChecker package app.aaps.plugins.constraints.versionChecker
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import app.aaps.plugins.constraints.versionChecker.AllowedVersions
import org.joda.time.LocalDate
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
class AllowedVersionsTest { class AllowedVersionsTest {
@ -71,10 +72,10 @@ class AllowedVersionsTest {
@Test @Test
fun endDateToMilliseconds() { fun endDateToMilliseconds() {
val definition = generateSupportedVersions() val definition = generateSupportedVersions()
val endDate = AllowedVersions().endDateToMilliseconds(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate") ?: "1000/01/01") val endDate = AllowedVersions().endDateToMilliseconds(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate") ?: "1000/01/01") ?: 0L
val dateTime = LocalDate(endDate) val dateTime = LocalDate.ofInstant(Instant.ofEpochMilli(endDate), ZoneId.systemDefault())
assertThat(dateTime.year).isEqualTo(2021) assertThat(dateTime.year).isEqualTo(2021)
assertThat(dateTime.monthOfYear).isEqualTo(11) assertThat(dateTime.monthValue).isEqualTo(11)
assertThat(dateTime.dayOfMonth).isEqualTo(7) assertThat(dateTime.dayOfMonth).isEqualTo(7)
assertThat(AllowedVersions().endDateToMilliseconds("abdef")).isNull() assertThat(AllowedVersions().endDateToMilliseconds("abdef")).isNull()