Skip to content

Commit

Permalink
Merge pull request #67 from ReneeVandervelde/fixed-clock
Browse files Browse the repository at this point in the history
Add FixedClock implementation
  • Loading branch information
ReneeVandervelde authored Jan 4, 2025
2 parents 4111a0f + a750f91 commit 3b3cd51
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Change Log
- Added `Instant.toZonedDateTime` extension to convert an `Instant` to a
`ZonedDateTime` in a specific timezone without needing to do multiple
conversions.
- Added `FixedClock` class to provide a simple syntax for creating a
clock with a static time. This is particularly useful in combination
with the Zoned clock implementation, since an anonymous interface
conversion is cumbersome to convert.

1.8.1
-----
Expand Down
10 changes: 10 additions & 0 deletions datetime/api/datetime.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
public final class com/inkapplications/datetime/FixedClock : kotlinx/datetime/Clock {
public fun <init> (Lkotlinx/datetime/Instant;)V
public final fun copy (Lkotlinx/datetime/Instant;)Lcom/inkapplications/datetime/FixedClock;
public static synthetic fun copy$default (Lcom/inkapplications/datetime/FixedClock;Lkotlinx/datetime/Instant;ILjava/lang/Object;)Lcom/inkapplications/datetime/FixedClock;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun now ()Lkotlinx/datetime/Instant;
public fun toString ()Ljava/lang/String;
}

public final class com/inkapplications/datetime/ZonedClock : kotlinx/datetime/Clock {
public static final field Companion Lcom/inkapplications/datetime/ZonedClock$Companion;
public fun <init> (Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.inkapplications.datetime

import kotlinx.datetime.Clock
import kotlinx.datetime.Instant

/**
* A static implementation of a Clock.
*
* This is primarily useful to simplify syntax in tests.
*/
data class FixedClock(
private val fixedTime: Instant,
): Clock {
override fun now(): Instant = fixedTime
}

0 comments on commit 3b3cd51

Please sign in to comment.