Skip to content

Commit 6679322

Browse files
authored
Merge branch 'main' into release-2.2.0
2 parents 949e442 + 9bac11b commit 6679322

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • kotlinx.interval.datetime/src/commonTest/kotlin

kotlinx.interval.datetime/src/commonTest/kotlin/Readme.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,19 @@ class Readme
2828
val uiPercentage: Double = timelineUi.getPercentageFor( mouseX )
2929
val selectedTime: Instant = year2025.getValueAt( uiPercentage ) // July 2nd at noon.
3030
}
31+
32+
@Test
33+
fun introduction_common_math()
34+
{
35+
// Two intervals of different types.
36+
val start2025 = LocalDateTime( 2025, 1, 1, 0, 0 ).toInstant( TimeZone.UTC )
37+
val end2025 = LocalDateTime( 2026, 1, 1, 0, 0 ).toInstant( TimeZone.UTC )
38+
val year2025: InstantInterval = interval( start2025, end2025 )
39+
val timelineUi: IntInterval = interval( 0, 800 ) // UI element 800 pixels wide
40+
41+
// Find the selected time at a given UI coordinate using linear interpolation.
42+
val mouseX = 400
43+
val uiPercentage: Double = timelineUi.getPercentageFor( mouseX )
44+
val selectedTime: Instant = year2025.getValueAt( uiPercentage ) // July 2nd at noon.
45+
}
3146
}

0 commit comments

Comments
 (0)