From 2049adf468aeb2292f8955bd6bcae8de5cd75a00 Mon Sep 17 00:00:00 2001 From: Tozy Fullbuster Date: Thu, 26 Oct 2023 10:58:10 +0700 Subject: [PATCH] feat: snowflake extension --- common/src/commonMain/kotlin/entity/Snowflake.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/src/commonMain/kotlin/entity/Snowflake.kt b/common/src/commonMain/kotlin/entity/Snowflake.kt index 07a1f2a06ab..b74fd40d5b0 100644 --- a/common/src/commonMain/kotlin/entity/Snowflake.kt +++ b/common/src/commonMain/kotlin/entity/Snowflake.kt @@ -242,3 +242,17 @@ private class SnowflakeTimeMark(private val timestamp: Instant) : TimeMark { * Values are [coerced in][coerceIn] [validValues]. */ public fun Snowflake(value: Long): Snowflake = Snowflake(value.coerceAtLeast(0).toULong()) + +/** + * Creates a [Snowflake] from this [Long] number. + * + * Values are [coerced in][coerceIn] [validValues]. + */ +public fun Long.snowflake(): Snowflake = Snowflake(this) + +/** + * Creates a [Snowflake] from this [ULong] number. + * + * Values are [coerced in][coerceIn] [validValues]. + */ +public fun ULong.snowflake(): Snowflake = Snowflake(this)