Skip to content

Commit

Permalink
Merge pull request #9 from teogor/bugfix/api26-systemzoneoffset-build…
Browse files Browse the repository at this point in the history
…localtime

Introduce API level 26 requirements for `systemZoneOffset` and `buildLocalDateTime`
  • Loading branch information
teogor authored Feb 23, 2024
2 parents d81541b + 3967887 commit 525b3c9
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package dev.teogor.querent.tasks

import androidx.annotation.RequiresApi
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
Expand All @@ -38,6 +40,7 @@ abstract class GenerateBuildProfileFileTask : BaseTask() {

private val BuildVariant by lazy { packageName.get() type "BuildVariant" }
private val BuildProfiler by lazy { "dev.teogor.ceres.core.register" type "BuildProfiler" }
private val ANDROID_OS_BUILD by lazy { "android.os" type "Build" }

@get:Input
abstract val debug: Property<Boolean>
Expand Down Expand Up @@ -177,6 +180,14 @@ abstract class GenerateBuildProfileFileTask : BaseTask() {
)
.getter(
FunSpec.getterBuilder()
.addAnnotation(
AnnotationSpec.builder(RequiresApi::class)
.addMember(
"%T.VERSION_CODES.O",
ANDROID_OS_BUILD,
)
.build(),
)
.addCode(
"return %T.systemDefault().rules.getOffset(%T.now())",
ZoneId::class,
Expand All @@ -199,6 +210,14 @@ abstract class GenerateBuildProfileFileTask : BaseTask() {
)
.getter(
FunSpec.getterBuilder()
.addAnnotation(
AnnotationSpec.builder(RequiresApi::class)
.addMember(
"%T.VERSION_CODES.O",
ANDROID_OS_BUILD,
)
.build(),
)
.addCode(
"return %T.ofEpochSecond(buildTime, 0, systemZoneOffset)",
LocalDateTime::class,
Expand Down

0 comments on commit 525b3c9

Please sign in to comment.