Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ManualClock to Test Module #204

Merged
merged 3 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/api/test.api
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public final class com/juul/tuulbox/test/AssertKt {
public static synthetic fun assertSimilar-dWUq8MI$default (Lkotlinx/datetime/LocalDateTime;JLkotlinx/datetime/LocalDateTime;Lkotlinx/datetime/TimeZone;ILjava/lang/Object;)V
}

public final class com/juul/tuulbox/test/ManualClock : kotlinx/datetime/Clock {
public fun <init> ()V
public fun <init> (Lkotlinx/datetime/Instant;)V
public synthetic fun <init> (Lkotlinx/datetime/Instant;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lkotlinx/datetime/LocalDateTime;Lkotlinx/datetime/TimeZone;)V
public fun now ()Lkotlinx/datetime/Instant;
public final fun set (Lkotlinx/datetime/Instant;)V
public final fun set (Lkotlinx/datetime/LocalDateTime;Lkotlinx/datetime/TimeZone;)V
}

public final class com/juul/tuulbox/test/RunTestKt {
public static final fun runTest (Lkotlin/jvm/functions/Function2;)V
}
Expand Down
32 changes: 32 additions & 0 deletions test/src/commonMain/kotlin/ManualClock.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.juul.tuulbox.test

import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant

private val defaultTime: Instant = LocalDateTime(
year = 2022,
monthNumber = 3,
dayOfMonth = 8,
hour = 8,
minute = 15,
).toInstant(TimeZone.UTC)

public class ManualClock(
private var time: Instant = defaultTime
) : Clock {
davertay-j marked this conversation as resolved.
Show resolved Hide resolved

public constructor(time: LocalDateTime, timeZone: TimeZone) : this(time.toInstant(timeZone))

override fun now(): Instant = time

public fun set(to: Instant) {
time = to
}

public fun set(to: LocalDateTime, timeZone: TimeZone) {
time = to.toInstant(timeZone)
}
}