From 68753a6e7225ac2f85c687da15b01cee578ba759 Mon Sep 17 00:00:00 2001 From: Erik Christensen <40830816+erikc5000@users.noreply.github.com> Date: Thu, 30 Jul 2020 12:05:50 -0400 Subject: [PATCH] Remove threentenabp-extensions (#112) --- buildSrc/src/main/kotlin/Dependencies.kt | 2 - docs/advanced/custom-providers.md | 7 + docs/extensions/threetenabp.md | 45 --- docs/getting-started.md | 10 +- extensions/threetenabp/build.gradle.kts | 34 -- extensions/threetenabp/gradle.properties | 5 - .../extensions/threetenabp/ProviderTest.kt | 31 -- .../threetenabp/src/main/AndroidManifest.xml | 3 - .../threetenabp/AndroidThreeTenProvider.kt | 134 ------- .../extensions/threetenabp/Conversions.kt | 351 ------------------ .../threetenabp/JavaSanityTest.java | 31 -- .../extensions/threetenabp/ConversionsTest.kt | 263 ------------- mkdocs.yml | 1 - 13 files changed, 9 insertions(+), 908 deletions(-) delete mode 100644 docs/extensions/threetenabp.md delete mode 100644 extensions/threetenabp/build.gradle.kts delete mode 100644 extensions/threetenabp/gradle.properties delete mode 100644 extensions/threetenabp/src/androidTest/kotlin/io/islandtime/extensions/threetenabp/ProviderTest.kt delete mode 100644 extensions/threetenabp/src/main/AndroidManifest.xml delete mode 100644 extensions/threetenabp/src/main/kotlin/io/islandtime/extensions/threetenabp/AndroidThreeTenProvider.kt delete mode 100644 extensions/threetenabp/src/main/kotlin/io/islandtime/extensions/threetenabp/Conversions.kt delete mode 100644 extensions/threetenabp/src/test/java/io/islandtime/extensions/threetenabp/JavaSanityTest.java delete mode 100644 extensions/threetenabp/src/test/kotlin/io/islandtime/extensions/threetenabp/ConversionsTest.kt diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index dc2b51e98..ad5eefe06 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -4,7 +4,6 @@ object Versions { const val atomicfu = "0.14.2" const val androidxTest = "1.2.0" const val googleTruth = "1.0.1" - const val threetenabp = "1.2.4" const val kotlinpoet = "1.6.0" const val androidDesugarJdkLibs = "1.0.9" } @@ -27,7 +26,6 @@ object Libs { } const val googleTruth = "com.google.truth:truth:${Versions.googleTruth}" - const val threetenabp = "com.jakewharton.threetenabp:threetenabp:${Versions.threetenabp}" const val kotlinpoet = "com.squareup:kotlinpoet:${Versions.kotlinpoet}" const val androidDesugarJdkLibs = "com.android.tools:desugar_jdk_libs:${Versions.androidDesugarJdkLibs}" } \ No newline at end of file diff --git a/docs/advanced/custom-providers.md b/docs/advanced/custom-providers.md index 755f9159a..d60771e18 100644 --- a/docs/advanced/custom-providers.md +++ b/docs/advanced/custom-providers.md @@ -13,4 +13,11 @@ IslandTime.initialize { dateTimeTextProvider = MyDateTimeTextProvider timeZoneTextProvider = MyTimeZoneTextProvider } +``` + +Island Time can only be initialized once. Subsequent attempts to initialize it will throw an exception. This is intended to alert you to potentially undesirable behavior as a result of late initialization or attempts to use different providers in different places. In a test environment though, this can sometimes be problematic, so you may explciitly restore Island Time to an unitialized state using the `reset()` function: + +```kotlin +IslandTime.reset() +// It's now safe to initialize Island Time again ``` \ No newline at end of file diff --git a/docs/extensions/threetenabp.md b/docs/extensions/threetenabp.md deleted file mode 100644 index 5ed35dace..000000000 --- a/docs/extensions/threetenabp.md +++ /dev/null @@ -1,45 +0,0 @@ -# ThreeTen Android Backport - -Island Time normally depends on the java.time API to access time zone database information, but this is only available in Android API level 26 and above. While Android Studio 4.0's core library desugaring will alleviate this problem soon, in the interim, the `threetenabp-extensions` artifact provides support for using the [Android JSR-310 Backport](https://github.com/JakeWharton/ThreeTenABP) instead. - -## Gradle Setup - -Add the following Android-only dependency to your project's Gradle script: - -=== "Groovy" - ```groovy - dependencies { - implementation "io.islandtime:threetenabp-extensions:{{ versions.islandtime }}" - } - ``` - -=== "Kotlin" - ```kotlin - dependencies { - implementation("io.islandtime:threetenabp-extensions:{{ versions.islandtime }}") - } - ``` - -## Initialization - -You need to initialize Island Time with the [AndroidThreeTenProvider](../api/threetenabp/io.islandtime.extensions.threetenabp/-android-three-ten-provider/index.md) before using any of the library's functionality. Generally, you'll want to do this during `Application.onCreate()`. - -```kotlin -// Note that it isn't necessary to call AndroidThreeTen.init() separately -IslandTime.initialize { - timeZoneRulesProvider = AndroidThreeTenProvider(context) -} -``` - -Island Time can only be initialized once. Subsequent attempts to initialize it will throw an exception. This is intended to alert you to potentially undesirable behavior as a result of late initialization or attempts to use different providers in different places. In a test environment though, this can sometimes be problematic, so you may explciitly restore Island Time to an unitialized state using the `reset()` function: - -```kotlin -IslandTime.reset() -// It's now safe to initialize Island Time again -``` - -For more information, see [Custom Providers](../advanced/custom-providers.md). - -## Additional Extensions - -In addition to the time zone database provider, there is also a set of extension methods allowing you to convert between Island Time types and equivalent Java types in the `org.threeten.bp` namespace. Consult the [API docs](../api/threetenabp/io.islandtime.extensions.threetenabp/index.md) for more details. \ No newline at end of file diff --git a/docs/getting-started.md b/docs/getting-started.md index 52804f234..e58118687 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -32,7 +32,7 @@ Island Time requires Java 8 or above. ### Android -Island Time requires a minimum compile SDK of API 15 or later and Java 8 support should be [turned on](https://developer.android.com/studio/write/java8-support). +Island Time requires Android Gradle Plugin 4.0 or later and a minimum compile SDK of API 15. ## Gradle Setup @@ -61,9 +61,7 @@ Extensions are also available for [serialization](extensions/serialization.md) a ### Android -#### Android Studio 4.0 or later - -Make sure that [core library desugaring](https://developer.android.com/studio/preview/features#j8-desugar) is enabled. +You'll need to turn on [core library desugaring](https://developer.android.com/studio/preview/features#j8-desugar) if it isn't enabled already. === "Groovy" ```groovy @@ -109,10 +107,6 @@ Make sure that [core library desugaring](https://developer.android.com/studio/pr } ``` -#### Android Studio 3.6 or earlier - -You'll need to add an additional dependency on the ThreeTen Android Backport. You can find details [here](extensions/threetenabp.md). - ### Snapshot builds Development snapshot builds are available in the Sonatype OSS Snapshot Repository. To use one, you'll need to add that repository to your project's Gradle script: diff --git a/extensions/threetenabp/build.gradle.kts b/extensions/threetenabp/build.gradle.kts deleted file mode 100644 index 6c4de87fd..000000000 --- a/extensions/threetenabp/build.gradle.kts +++ /dev/null @@ -1,34 +0,0 @@ -plugins { - `android-library` -} - -android { - sourceSets { - getByName("main").java.srcDirs("src/main/kotlin") - getByName("test").java.srcDirs("src/test/java", "src/test/kotlin") - getByName("androidTest").java.srcDirs("src/androidTest/kotlin") - } - - defaultConfig { - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - } - - testOptions { - execution = "ANDROIDX_TEST_ORCHESTRATOR" - } -} - -dependencies { - implementation(project(":core")) - implementation(kotlin("stdlib-jdk8")) - - api(Libs.threetenabp) - - testImplementation(kotlin("test")) - testImplementation(kotlin("test-junit")) - testImplementation(Libs.googleTruth) - - androidTestImplementation(Libs.AndroidxTest.runner) - androidTestImplementation(Libs.googleTruth) - androidTestUtil(Libs.AndroidxTest.orchestrator) -} \ No newline at end of file diff --git a/extensions/threetenabp/gradle.properties b/extensions/threetenabp/gradle.properties deleted file mode 100644 index 389818399..000000000 --- a/extensions/threetenabp/gradle.properties +++ /dev/null @@ -1,5 +0,0 @@ -pomName=Island Time ThreetenAbp Extensions -pomDescription=Integration with the Android backport of the java.time library -pomArtifactId=threetenabp-extensions - -android.useAndroidX=true \ No newline at end of file diff --git a/extensions/threetenabp/src/androidTest/kotlin/io/islandtime/extensions/threetenabp/ProviderTest.kt b/extensions/threetenabp/src/androidTest/kotlin/io/islandtime/extensions/threetenabp/ProviderTest.kt deleted file mode 100644 index 19712eb6b..000000000 --- a/extensions/threetenabp/src/androidTest/kotlin/io/islandtime/extensions/threetenabp/ProviderTest.kt +++ /dev/null @@ -1,31 +0,0 @@ -package io.islandtime.extensions.threetenabp - -import org.junit.Test -import androidx.test.platform.app.InstrumentationRegistry -import com.google.common.truth.Truth.assertThat -import io.islandtime.IslandTime -import io.islandtime.zone.TimeZoneRulesProvider -import org.junit.After - -class AndroidThreeTenProviderTest { - private val context = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext - - @After - fun tearDown() { - IslandTime.reset() - } - - @Test - fun sanityCheck() { - IslandTime.initializeWith(AndroidThreeTenProvider(context)) - - assertThat(TimeZoneRulesProvider.databaseVersion).isNotEmpty() - assertThat(TimeZoneRulesProvider.availableRegionIds).isNotEmpty() - } - - @Test(expected = IllegalStateException::class) - fun doubleInitializationCausesException() { - IslandTime.initializeWith(AndroidThreeTenProvider(context)) - IslandTime.initializeWith(AndroidThreeTenProvider(context)) - } -} \ No newline at end of file diff --git a/extensions/threetenabp/src/main/AndroidManifest.xml b/extensions/threetenabp/src/main/AndroidManifest.xml deleted file mode 100644 index 1e9b46d3d..000000000 --- a/extensions/threetenabp/src/main/AndroidManifest.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/extensions/threetenabp/src/main/kotlin/io/islandtime/extensions/threetenabp/AndroidThreeTenProvider.kt b/extensions/threetenabp/src/main/kotlin/io/islandtime/extensions/threetenabp/AndroidThreeTenProvider.kt deleted file mode 100644 index 6200a8849..000000000 --- a/extensions/threetenabp/src/main/kotlin/io/islandtime/extensions/threetenabp/AndroidThreeTenProvider.kt +++ /dev/null @@ -1,134 +0,0 @@ -package io.islandtime.extensions.threetenabp - -import android.app.Application -import android.content.Context -import com.jakewharton.threetenabp.AndroidThreeTen -import io.islandtime.* -import io.islandtime.measures.* -import io.islandtime.zone.TimeZoneOffsetTransition -import io.islandtime.zone.TimeZoneRules -import io.islandtime.zone.TimeZoneRulesException -import io.islandtime.zone.TimeZoneRulesProvider -import org.threeten.bp.Instant as JavaInstant -import org.threeten.bp.zone.ZoneOffsetTransition -import org.threeten.bp.zone.ZoneRules -import org.threeten.bp.zone.ZoneRulesException -import org.threeten.bp.zone.ZoneRulesProvider - -/** - * A time zone rules provider that draws from the DB packaged with ThreeTenABP. - */ -class AndroidThreeTenProvider(context: Context, assetPath: String) : TimeZoneRulesProvider { - init { - if (assetPath.isNotEmpty()) { - AndroidThreeTen.init(context, assetPath) - } else { - AndroidThreeTen.init(context) - } - } - - constructor(context: Context) : this(context, "") - constructor(application: Application) : this(application as Context) - - override val databaseVersion: String - get() = try { - ZoneRulesProvider.getVersions("Etc/UTC")?.lastEntry()?.key.orEmpty() - } catch (e: ZoneRulesException) { - throw TimeZoneRulesException(e.message, e) - } - - override val availableRegionIds: Set - get() = ZoneRulesProvider.getAvailableZoneIds() - - override fun hasRulesFor(regionId: String): Boolean { - return availableRegionIds.contains(regionId) - } - - override fun rulesFor(regionId: String): TimeZoneRules { - return try { - JavaTimeZoneRules(ZoneRulesProvider.getRules(regionId, false)) - } catch (e: ZoneRulesException) { - throw TimeZoneRulesException(e.message, e) - } - } -} - -private class JavaTimeZoneRules( - private val javaZoneRules: ZoneRules -) : TimeZoneRules { - - override fun offsetAt(millisecondsSinceUnixEpoch: LongMilliseconds): UtcOffset { - val offset = javaZoneRules.getOffset(JavaInstant.ofEpochMilli(millisecondsSinceUnixEpoch.value)) - return offset.toIslandUtcOffset() - } - - override fun offsetAt(secondsSinceUnixEpoch: LongSeconds, nanoOfSeconds: IntNanoseconds): UtcOffset { - val offset = javaZoneRules.getOffset( - JavaInstant.ofEpochSecond(secondsSinceUnixEpoch.value, nanoOfSeconds.value.toLong()) - ) - return offset.toIslandUtcOffset() - } - - override fun offsetAt(instant: Instant): UtcOffset { - val offset = javaZoneRules.getOffset(instant.toJavaInstant()) - return offset.toIslandUtcOffset() - } - - override fun offsetAt(dateTime: DateTime): UtcOffset { - val offset = javaZoneRules.getOffset(dateTime.toJavaLocalDateTime()) - return offset.toIslandUtcOffset() - } - - override fun validOffsetsAt(dateTime: DateTime): List { - val offsets = javaZoneRules.getValidOffsets(dateTime.toJavaLocalDateTime()) - return offsets.map { it.toIslandUtcOffset() } - } - - override fun transitionAt(dateTime: DateTime): TimeZoneOffsetTransition? { - val transition = javaZoneRules.getTransition(dateTime.toJavaLocalDateTime()) - return if (transition != null) JavaTimeZoneOffsetTransition(transition) else null - } - - override fun isValidOffset( - dateTime: DateTime, - offset: UtcOffset - ): Boolean { - return javaZoneRules.isValidOffset(dateTime.toJavaLocalDateTime(), offset.toJavaZoneOffset()) - } - - override fun isDaylightSavingsAt(instant: Instant): Boolean { - return javaZoneRules.isDaylightSavings(instant.toJavaInstant()) - } - - override fun daylightSavingsAt(instant: Instant): IntSeconds { - return javaZoneRules.getDaylightSavings(instant.toJavaInstant()).seconds.toInt().seconds - } - - override val hasFixedOffset: Boolean get() = javaZoneRules.isFixedOffset -} - -private class JavaTimeZoneOffsetTransition( - private val javaZoneOffsetTransition: ZoneOffsetTransition -) : TimeZoneOffsetTransition { - - override val dateTimeBefore: DateTime - get() = javaZoneOffsetTransition.dateTimeBefore.toIslandDateTime() - - override val dateTimeAfter: DateTime - get() = javaZoneOffsetTransition.dateTimeAfter.toIslandDateTime() - - override val offsetBefore: UtcOffset - get() = javaZoneOffsetTransition.offsetBefore.toIslandUtcOffset() - - override val offsetAfter: UtcOffset - get() = javaZoneOffsetTransition.offsetAfter.toIslandUtcOffset() - - override val duration: IntSeconds - get() = offsetAfter.totalSeconds - offsetBefore.totalSeconds - - override val isGap: Boolean - get() = javaZoneOffsetTransition.isGap - - override val isOverlap: Boolean - get() = javaZoneOffsetTransition.isOverlap -} \ No newline at end of file diff --git a/extensions/threetenabp/src/main/kotlin/io/islandtime/extensions/threetenabp/Conversions.kt b/extensions/threetenabp/src/main/kotlin/io/islandtime/extensions/threetenabp/Conversions.kt deleted file mode 100644 index 546df1325..000000000 --- a/extensions/threetenabp/src/main/kotlin/io/islandtime/extensions/threetenabp/Conversions.kt +++ /dev/null @@ -1,351 +0,0 @@ -@file:JvmName("IslandTimeUtils") - -package io.islandtime.extensions.threetenabp - -import io.islandtime.* -import io.islandtime.measures.* - -/** - * Convert to an equivalent Island Time [Instant]. - */ -fun org.threeten.bp.Instant.toIslandInstant(): Instant { - return Instant.fromSecondOfUnixEpoch(epochSecond, nano) -} - -/** - * Convert to an equivalent Java `Instant`. - */ -fun Instant.toJavaInstant(): org.threeten.bp.Instant { - return org.threeten.bp.Instant.ofEpochSecond(secondOfUnixEpoch, nanosecond.toLong()) -} - -/** - * Convert to an equivalent Island Time [Date]. - */ -fun org.threeten.bp.LocalDate.toIslandDate(): Date { - return Date(year, monthValue, dayOfMonth) -} - -/** - * Convert to an equivalent Java `LocalDate`. - */ -fun Date.toJavaLocalDate(): org.threeten.bp.LocalDate { - return org.threeten.bp.LocalDate.of(year, monthNumber, dayOfMonth) -} - -/** - * Convert to an equivalent Island Time [Time]. - */ -fun org.threeten.bp.LocalTime.toIslandTime(): Time { - return Time(hour, minute, second, nano) -} - -/** - * Convert to an equivalent Java `LocalTime`. - */ -fun Time.toJavaLocalTime(): org.threeten.bp.LocalTime { - return org.threeten.bp.LocalTime.of(hour, minute, second, nanosecond) -} - -/** - * Convert to an equivalent Island Time [DateTime]. - */ -fun org.threeten.bp.LocalDateTime.toIslandDateTime(): DateTime { - return DateTime( - Date(year, monthValue, dayOfMonth), - Time(hour, minute, second, nano) - ) -} - -/** - * Convert to an equivalent Java `LocalDateTime`. - */ -fun DateTime.toJavaLocalDateTime(): org.threeten.bp.LocalDateTime { - return org.threeten.bp.LocalDateTime.of(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond) -} - -/** - * Convert to an equivalent Island Time [OffsetTime]. - */ -fun org.threeten.bp.OffsetTime.toIslandOffsetTime(): OffsetTime { - return OffsetTime( - Time(hour, minute, second, nano), - UtcOffset(offset.totalSeconds.seconds) - ) -} - -/** - * Convert to an equivalent Java `OffsetTime`. - */ -fun OffsetTime.toJavaOffsetTime(): org.threeten.bp.OffsetTime { - return org.threeten.bp.OffsetTime.of( - org.threeten.bp.LocalTime.of(hour, minute, second, nanosecond), - org.threeten.bp.ZoneOffset.ofTotalSeconds(offset.totalSeconds.value) - ) -} - -/** - * Convert to an equivalent Island Time [OffsetDateTime]. - */ -fun org.threeten.bp.OffsetDateTime.toIslandOffsetDateTime(): OffsetDateTime { - return OffsetDateTime( - DateTime( - Date(year, monthValue, dayOfMonth), - Time(hour, minute, second, nano) - ), - UtcOffset(offset.totalSeconds.seconds) - ) -} - -/** - * Convert to an equivalent Java `OffsetDateTime`. - */ -fun OffsetDateTime.toJavaOffsetDateTime(): org.threeten.bp.OffsetDateTime { - return org.threeten.bp.OffsetDateTime.of( - org.threeten.bp.LocalDateTime.of(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond), - org.threeten.bp.ZoneOffset.ofTotalSeconds(offset.totalSeconds.value) - ) -} - -/** - * Convert to an equivalent Island Time [ZonedDateTime]. - */ -fun org.threeten.bp.ZonedDateTime.toIslandZonedDateTime(): ZonedDateTime { - return ZonedDateTime.fromLocal( - DateTime( - Date(year, monthValue, dayOfMonth), - Time(hour, minute, second, nano) - ), - zone.toIslandTimeZone(), - UtcOffset(offset.totalSeconds.seconds) - ) -} - -/** - * Convert to an equivalent Java `ZonedDateTime`. - */ -fun ZonedDateTime.toJavaZonedDateTime(): org.threeten.bp.ZonedDateTime { - return org.threeten.bp.ZonedDateTime.ofLocal( - org.threeten.bp.LocalDateTime.of(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond), - org.threeten.bp.ZoneId.of(zone.id), - org.threeten.bp.ZoneOffset.ofTotalSeconds(offset.totalSeconds.value) - ) -} - -/** - * Convert to an equivalent Island Time [UtcOffset]. - */ -fun org.threeten.bp.ZoneOffset.toIslandUtcOffset(): UtcOffset { - return UtcOffset(totalSeconds.seconds) -} - -/** - * Convert to an equivalent Java `ZoneOffset`. - */ -fun UtcOffset.toJavaZoneOffset(): org.threeten.bp.ZoneOffset { - return org.threeten.bp.ZoneOffset.ofTotalSeconds(totalSeconds.value) -} - -/** - * Convert to an equivalent Java `ZoneId`. - */ -fun TimeZone.toJavaZoneId(): org.threeten.bp.ZoneId { - return org.threeten.bp.ZoneId.of(id) -} - -/** - * Convert to an equivalent Island Time [TimeZone]. - */ -fun org.threeten.bp.ZoneId.toIslandTimeZone(): TimeZone { - return TimeZone(id) -} - -/** - * Convert to an equivalent Island Time [Duration]. - */ -fun org.threeten.bp.Duration.toIslandDuration(): Duration { - return durationOf(seconds.seconds, nano.nanoseconds) -} - -/** - * Convert to an equivalent Java `Duration`. - */ -fun Duration.toJavaDuration(): org.threeten.bp.Duration { - return org.threeten.bp.Duration.ofSeconds(seconds.value, nanosecondAdjustment.value.toLong()) -} - -/** - * Convert to an equivalent Island Time [Period]. - */ -fun org.threeten.bp.Period.toIslandPeriod(): Period { - return periodOf(years.years, months.months, days.days) -} - -/** - * Convert to an equivalent Java `Period`. - */ -fun Period.toJavaPeriod(): org.threeten.bp.Period { - return org.threeten.bp.Period.of(years.value, months.value, days.value) -} - -/** - * Convert to an equivalent Island Time [YearMonth]. - */ -fun org.threeten.bp.YearMonth.toIslandYearMonth(): YearMonth { - return YearMonth(year, monthValue) -} - -/** - * Convert to an equivalent Java `YearMonth`. - */ -fun YearMonth.toJavaYearMonth(): org.threeten.bp.YearMonth { - return org.threeten.bp.YearMonth.of(year, monthNumber) -} - -/** - * Convert to an equivalent Island Time [Year]. - */ -fun org.threeten.bp.Year.toIslandYear(): Year { - return Year(value) -} - -/** - * Convert to an equivalent Java `Year`. - */ -fun Year.toJavaYear(): org.threeten.bp.Year { - return org.threeten.bp.Year.of(value) -} - -/** - * Convert to an equivalent Java `Period`. - */ -fun IntCenturies.toJavaPeriod(): org.threeten.bp.Period = this.inYears.toJavaPeriod() - -/** - * Convert to an equivalent Java `Period`. - */ -fun LongCenturies.toJavaPeriod(): org.threeten.bp.Period = this.inYears.toJavaPeriod() - -/** - * Convert to an equivalent Java `Period`. - */ -fun IntDecades.toJavaPeriod(): org.threeten.bp.Period = this.inYears.toJavaPeriod() - -/** - * Convert to an equivalent Java `Period`. - */ -fun LongDecades.toJavaPeriod(): org.threeten.bp.Period = this.inYears.toJavaPeriod() - -/** - * Convert to an equivalent Java `Period`. - */ -fun IntYears.toJavaPeriod(): org.threeten.bp.Period = org.threeten.bp.Period.ofYears(value) - -/** - * Convert to an equivalent Java `Period`. - */ -fun LongYears.toJavaPeriod(): org.threeten.bp.Period = this.toIntYears().toJavaPeriod() - -/** - * Convert to an equivalent Java `Period`. - */ -fun IntMonths.toJavaPeriod(): org.threeten.bp.Period = org.threeten.bp.Period.ofMonths(value) - -/** - * Convert to an equivalent Java `Period`. - */ -fun LongMonths.toJavaPeriod(): org.threeten.bp.Period = this.toIntMonths().toJavaPeriod() - -/** - * Convert to an equivalent Java `Period`. - */ -fun IntWeeks.toJavaPeriod(): org.threeten.bp.Period = org.threeten.bp.Period.ofWeeks(value) - -/** - * Convert to an equivalent Java `Period`. - */ -fun LongWeeks.toJavaPeriod(): org.threeten.bp.Period = this.toIntWeeks().toJavaPeriod() - -/** - * Convert to an equivalent Java `Period`. - */ -fun IntDays.toJavaPeriod(): org.threeten.bp.Period = org.threeten.bp.Period.ofDays(value) - -/** - * Convert to an equivalent Java `Period`. - */ -fun LongDays.toJavaPeriod(): org.threeten.bp.Period = this.toIntDays().toJavaPeriod() - -/** - * Convert to an equivalent Java `Duration`. - */ -fun IntDays.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofDays(value.toLong()) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun LongDays.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofDays(value) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun IntHours.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofHours(value.toLong()) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun LongHours.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofHours(value) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun IntMinutes.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofMinutes(value.toLong()) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun LongMinutes.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofMinutes(value) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun IntSeconds.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofSeconds(value.toLong()) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun LongSeconds.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofSeconds(value) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun IntMilliseconds.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofMillis(value.toLong()) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun LongMilliseconds.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofMillis(value) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun IntMicroseconds.toJavaDuration(): org.threeten.bp.Duration = this.toLongMicroseconds().toJavaDuration() - -/** - * Convert to an equivalent Java `Duration`. - */ -fun LongMicroseconds.toJavaDuration(): org.threeten.bp.Duration { - val seconds = this.inSeconds - val nanoOfSeconds = (this % 1_000_000).inNanoseconds - return org.threeten.bp.Duration.ofSeconds(seconds.value, nanoOfSeconds.value) -} - -/** - * Convert to an equivalent Java `Duration`. - */ -fun IntNanoseconds.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofNanos(value.toLong()) - -/** - * Convert to an equivalent Java `Duration`. - */ -fun LongNanoseconds.toJavaDuration(): org.threeten.bp.Duration = org.threeten.bp.Duration.ofNanos(value) \ No newline at end of file diff --git a/extensions/threetenabp/src/test/java/io/islandtime/extensions/threetenabp/JavaSanityTest.java b/extensions/threetenabp/src/test/java/io/islandtime/extensions/threetenabp/JavaSanityTest.java deleted file mode 100644 index 3c2578b09..000000000 --- a/extensions/threetenabp/src/test/java/io/islandtime/extensions/threetenabp/JavaSanityTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.islandtime.extensions.threetenabp; - -import io.islandtime.Month; -import io.islandtime.Date; -import org.junit.Test; -import org.threeten.bp.LocalDate; - -import static com.google.common.truth.Truth.assertThat; -import static io.islandtime.extensions.threetenabp.IslandTimeUtils.*; - -public class JavaSanityTest { - @Test - public void convertIslandDateToJavaLocalDate() { - Date islandDate = new Date(2019, Month.MARCH, 1); - LocalDate javaDate = toJavaLocalDate(islandDate); - - assertThat(javaDate.getYear()).isEqualTo(islandDate.getYear()); - assertThat(javaDate.getMonthValue()).isEqualTo(islandDate.getMonth().getNumber()); - assertThat(javaDate.getDayOfMonth()).isEqualTo(islandDate.getDayOfMonth()); - } - - @Test - public void convertJavaLocalDateToIslandDate() { - LocalDate javaDate = LocalDate.of(2019, 3, 1); - Date islandDate = toIslandDate(javaDate); - - assertThat(islandDate.getYear()).isEqualTo(javaDate.getYear()); - assertThat(islandDate.getMonth().getNumber()).isEqualTo(javaDate.getMonthValue()); - assertThat(islandDate.getDayOfMonth()).isEqualTo(javaDate.getDayOfMonth()); - } -} \ No newline at end of file diff --git a/extensions/threetenabp/src/test/kotlin/io/islandtime/extensions/threetenabp/ConversionsTest.kt b/extensions/threetenabp/src/test/kotlin/io/islandtime/extensions/threetenabp/ConversionsTest.kt deleted file mode 100644 index f4cd9b5c0..000000000 --- a/extensions/threetenabp/src/test/kotlin/io/islandtime/extensions/threetenabp/ConversionsTest.kt +++ /dev/null @@ -1,263 +0,0 @@ -package io.islandtime.extensions.threetenabp - -import io.islandtime.* -import io.islandtime.measures.* -import kotlin.test.Test -import kotlin.test.assertEquals - -class ConversionsTest { - @Test - fun `converts Java Instant to Instant`() { - listOf( - org.threeten.bp.Instant.EPOCH to Instant.UNIX_EPOCH, - org.threeten.bp.Instant.ofEpochSecond(1, 999_999_999) to - Instant(1L.seconds, 999_999_999.nanoseconds), - org.threeten.bp.Instant.ofEpochSecond(-1) to Instant((-1L).seconds), - org.threeten.bp.Instant.ofEpochSecond(0, -999_999_999) to - Instant(0L.seconds, (-999_999_999).nanoseconds) - ).forEach { (javaInstant, islandInstant) -> - assertEquals(islandInstant, javaInstant.toIslandInstant()) - } - } - - @Test - fun `converts Instant to Java Instant`() { - listOf( - Instant.UNIX_EPOCH to org.threeten.bp.Instant.EPOCH, - Instant(1L.seconds, 999_999_999.nanoseconds) to - org.threeten.bp.Instant.ofEpochSecond(1, 999_999_999), - Instant((-1L).seconds) to org.threeten.bp.Instant.ofEpochSecond(-1), - Instant(0L.seconds, (-999_999_999).nanoseconds) to - org.threeten.bp.Instant.ofEpochSecond(0, -999_999_999) - ).forEach { (islandInstant, javaInstant) -> - assertEquals(javaInstant, islandInstant.toJavaInstant()) - } - } - - @Test - fun `converts Date to Java LocalDate`() { - val islandDate = Date(2019, Month.MAY, 3) - val javaDate = islandDate.toJavaLocalDate() - - assertEquals(islandDate.year, javaDate.year) - assertEquals(islandDate.monthNumber, javaDate.monthValue) - assertEquals(islandDate.dayOfMonth, javaDate.dayOfMonth) - } - - @Test - fun `converts Java LocalDate to Date`() { - val javaDate = org.threeten.bp.LocalDate.of(2019, org.threeten.bp.Month.MAY, 3) - val islandDate = javaDate.toIslandDate() - - assertEquals(javaDate.year, islandDate.year) - assertEquals(javaDate.monthValue, islandDate.monthNumber) - assertEquals(javaDate.dayOfMonth, islandDate.dayOfMonth) - } - - @Test - fun `converts Time to Java Time`() { - listOf( - Time.MIDNIGHT to org.threeten.bp.LocalTime.MIDNIGHT, - Time.NOON to org.threeten.bp.LocalTime.NOON, - Time.MAX to org.threeten.bp.LocalTime.MAX, - Time(1, 2, 3, 4) to - org.threeten.bp.LocalTime.of(1, 2, 3, 4) - ).forEach { (islandTime, javaTime) -> - assertEquals(javaTime, islandTime.toJavaLocalTime()) - } - } - - @Test - fun `converts Java Time to Time`() { - listOf( - org.threeten.bp.LocalTime.MIDNIGHT to Time.MIDNIGHT, - org.threeten.bp.LocalTime.NOON to Time.NOON, - org.threeten.bp.LocalTime.MAX to Time.MAX, - org.threeten.bp.LocalTime.of(1, 2, 3, 4) to - Time(1, 2, 3, 4) - ).forEach { (javaTime, islandTime) -> - assertEquals(islandTime, javaTime.toIslandTime()) - } - } - - @Test - fun `converts Java ZoneOffset to UtcOffset`() { - assertEquals( - UtcOffset(1.hours, 2.minutes, 3.seconds), - org.threeten.bp.ZoneOffset.ofHoursMinutesSeconds(1, 2, 3).toIslandUtcOffset() - ) - - assertEquals( - UtcOffset((-1).hours, (-2).minutes, (-3).seconds), - org.threeten.bp.ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3).toIslandUtcOffset() - ) - } - - @Test - fun `converts UtcOffset to Java ZoneOffset`() { - assertEquals( - org.threeten.bp.ZoneOffset.ofHoursMinutesSeconds(1, 2, 3), - UtcOffset(1.hours, 2.minutes, 3.seconds).toJavaZoneOffset() - ) - - assertEquals( - org.threeten.bp.ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3), - UtcOffset((-1).hours, (-2).minutes, (-3).seconds).toJavaZoneOffset() - ) - } - - @Test - fun `converts Java Duration to Duration`() { - assertEquals( - durationOf((-1).seconds, (-1).nanoseconds), - org.threeten.bp.Duration.ofSeconds(-1, -1).toIslandDuration() - ) - } - - @Test - fun `converts Duration to Java Duration`() { - assertEquals( - org.threeten.bp.Duration.ofSeconds(-1, -1), - durationOf((-1).seconds, (-1).nanoseconds).toJavaDuration() - ) - } - - @Test - fun `converts Java Period to Period`() { - assertEquals( - periodOf(1.years, 2.months, 3.days), - org.threeten.bp.Period.of(1, 2, 3).toIslandPeriod() - ) - } - - @Test - fun `converts Period to Java Period`() { - assertEquals( - org.threeten.bp.Period.of(1, 2, 3), - periodOf(1.years, 2.months, 3.days).toJavaPeriod() - ) - } - - @Test - fun `converts centuries to Java Period`() { - assertEquals(org.threeten.bp.Period.ZERO, 0.centuries.toJavaPeriod()) - assertEquals(org.threeten.bp.Period.ZERO, 0L.centuries.toJavaPeriod()) - - val period = 1.centuries.toJavaPeriod() - assertEquals(100, period.years) - assertEquals(0, period.months) - assertEquals(0, period.days) - } - - @Test - fun `converts decades to Java Period`() { - assertEquals(org.threeten.bp.Period.ZERO, 0.decades.toJavaPeriod()) - assertEquals(org.threeten.bp.Period.ZERO, 0L.decades.toJavaPeriod()) - - val period = 1.decades.toJavaPeriod() - assertEquals(10, period.years) - assertEquals(0, period.months) - assertEquals(0, period.days) - } - - @Test - fun `converts years to Java Period`() { - assertEquals(org.threeten.bp.Period.ZERO, 0.years.toJavaPeriod()) - assertEquals(org.threeten.bp.Period.ZERO, 0L.years.toJavaPeriod()) - - val period = 1.years.toJavaPeriod() - assertEquals(1, period.years) - assertEquals(0, period.months) - assertEquals(0, period.days) - } - - @Test - fun `converts months to Java Period`() { - assertEquals(org.threeten.bp.Period.ZERO, 0.months.toJavaPeriod()) - assertEquals(org.threeten.bp.Period.ZERO, 0L.months.toJavaPeriod()) - - val period = 1.months.toJavaPeriod() - assertEquals(0, period.years) - assertEquals(1, period.months) - assertEquals(0, period.days) - } - - @Test - fun `converts weeks to Java Period`() { - assertEquals(org.threeten.bp.Period.ZERO, 0.weeks.toJavaPeriod()) - assertEquals(org.threeten.bp.Period.ZERO, 0L.weeks.toJavaPeriod()) - - val period = 1.weeks.toJavaPeriod() - assertEquals(0, period.years) - assertEquals(0, period.months) - assertEquals(7, period.days) - } - - @Test - fun `converts days to Java Period`() { - assertEquals(org.threeten.bp.Period.ZERO, 0.days.toJavaPeriod()) - assertEquals(org.threeten.bp.Period.ZERO, 0L.days.toJavaPeriod()) - - val period = 1.days.toJavaPeriod() - assertEquals(0, period.years) - assertEquals(0, period.months) - assertEquals(1, period.days) - } - - @Test - fun `converts days to Java Duration`() { - assertEquals(org.threeten.bp.Duration.ZERO, 0.days.toJavaDuration()) - assertEquals(org.threeten.bp.Duration.ZERO, 0L.days.toJavaDuration()) - - assertEquals(1L, 1.days.toJavaDuration().toDays()) - assertEquals(-1L, (-1L).days.toJavaDuration().toDays()) - } - - @Test - fun `converts hours to Java Duration`() { - assertEquals(org.threeten.bp.Duration.ZERO, 0.hours.toJavaDuration()) - assertEquals(org.threeten.bp.Duration.ZERO, 0L.hours.toJavaDuration()) - assertEquals(1L, 1.hours.toJavaDuration().toHours()) - assertEquals(-1L, (-1L).hours.toJavaDuration().toHours()) - } - - @Test - fun `converts minutes to Java Duration`() { - assertEquals(org.threeten.bp.Duration.ZERO, 0.minutes.toJavaDuration()) - assertEquals(org.threeten.bp.Duration.ZERO, 0L.minutes.toJavaDuration()) - assertEquals(1L, 1.minutes.toJavaDuration().toMinutes()) - assertEquals(-1L, (-1L).minutes.toJavaDuration().toMinutes()) - } - - @Test - fun `converts seconds to Java Duration`() { - assertEquals(org.threeten.bp.Duration.ZERO, 0.seconds.toJavaDuration()) - assertEquals(org.threeten.bp.Duration.ZERO, 0L.seconds.toJavaDuration()) - assertEquals(1L, 1.seconds.toJavaDuration().seconds) - assertEquals(-1L, (-1L).seconds.toJavaDuration().seconds) - } - - @Test - fun `converts milliseconds to Java Duration`() { - assertEquals(org.threeten.bp.Duration.ZERO, 0.milliseconds.toJavaDuration()) - assertEquals(org.threeten.bp.Duration.ZERO, 0L.milliseconds.toJavaDuration()) - assertEquals(1_000_000_000L, 1_000_000_000.milliseconds.toJavaDuration().toMillis()) - assertEquals(-1L, (-1L).milliseconds.toJavaDuration().toMillis()) - } - - @Test - fun `converts microseconds to Java Duration`() { - assertEquals(org.threeten.bp.Duration.ZERO, 0.microseconds.toJavaDuration()) - assertEquals(org.threeten.bp.Duration.ZERO, 0L.microseconds.toJavaDuration()) - assertEquals(1_000_000_000L, 1_000_000_000.microseconds.toJavaDuration().toNanos() / 1000) - assertEquals(-1L, (-1L).microseconds.toJavaDuration().toNanos() / 1000) - } - - @Test - fun `converts nanoseconds to Java Duration`() { - assertEquals(org.threeten.bp.Duration.ZERO, 0.nanoseconds.toJavaDuration()) - assertEquals(org.threeten.bp.Duration.ZERO, 0L.nanoseconds.toJavaDuration()) - assertEquals(1_000_000_000L, 1_000_000_000.nanoseconds.toJavaDuration().toNanos()) - assertEquals(-1L, (-1L).nanoseconds.toJavaDuration().toNanos()) - } -} \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 28b5b0d50..ddaa72434 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -23,7 +23,6 @@ nav: - 'Extensions': - 'extensions/serialization.md' - 'extensions/parcelize.md' - - 'extensions/threetenabp.md' - 'API': - 'core': 'api/core/index.md' - 'parcelize-extensions': 'api/parcelize/index.md'