-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
145 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
cardinal-sdk/src/commonMain/kotlin/com/icure/cardinal/sdk/utils/Hex.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.icure.cardinal.sdk.utils | ||
|
||
private val DIGITS_RANGE = '0'.code .. '9'.code | ||
private val LOWERCASE_RANGE = 'a'.code .. 'f'.code | ||
private val UPPERCASE_RANGE = 'A'.code .. 'F'.code | ||
|
||
fun String.isValidHex() = | ||
length % 2 == 0 && all { c -> c.code.let { it in DIGITS_RANGE || it in LOWERCASE_RANGE || it in UPPERCASE_RANGE } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
cardinal-sdk/src/commonTest/kotlin/com/icure/cardinal/sdk/utils/time/ZonedDateTimeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.icure.cardinal.sdk.utils.time | ||
|
||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class ZonedDateTimeTest : StringSpec({ | ||
"Full zoned date time test" { | ||
listOf( | ||
Triple("2025-02-24T15:07:01.564571","-05:00", "America/New_York"), | ||
Triple("2025-02-24T15:07:01","Z", "UTC"), | ||
Triple("2025-02-24T15:07:01.564571","+01:00", "UT+01:00"), | ||
).forEach { (time, offset, zone) -> | ||
val format = "$time$offset[$zone]" | ||
val parsed = ZonedDateTime.fromIso8601AndZoneString(format) | ||
parsed.toIso8601AndZoneString() shouldBe format | ||
} | ||
} | ||
|
||
"Offset only zone test" { | ||
listOf( | ||
Pair("2025-02-24T15:06:08.886342","+01:00"), | ||
Pair("2025-02-24T15:06:08.886342","-02:30"), | ||
Pair("2025-02-24T12:00:01", "Z") | ||
).forEach { (time, offset) -> | ||
val format = "$time$offset" | ||
val parsed = ZonedDateTime.fromIso8601AndZoneString(format) | ||
parsed.toIso8601AndZoneString() shouldBe format | ||
parsed.zoneId.id shouldBe offset | ||
} | ||
} | ||
|
||
"Invalid input test" { | ||
listOf( | ||
"2025-02-24T12:00:12", | ||
"2025-02-24T12:00:12UTC", | ||
"2025-02-24T12:00:12-02:30[Europe/New_York]", | ||
"[America/New_York]", | ||
"-02:30", | ||
).forEach { | ||
shouldThrow<IllegalArgumentException> { ZonedDateTime.fromIso8601AndZoneString(it) } | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters