-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadme.kt
More file actions
31 lines (26 loc) · 1.12 KB
/
Readme.kt
File metadata and controls
31 lines (26 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@file:Suppress( "UNUSED_VARIABLE" )
package io.github.whathecode.kotlinx.interval.datetime
import io.github.whathecode.kotlinx.interval.InstantInterval
import io.github.whathecode.kotlinx.interval.IntInterval
import io.github.whathecode.kotlinx.interval.interval
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant
import kotlin.test.*
import kotlin.time.Instant
class Readme
{
@Test
fun introduction_common_math()
{
// Two intervals of different types.
val start2025 = LocalDateTime( 2025, 1, 1, 0, 0 ).toInstant( TimeZone.UTC )
val end2025 = LocalDateTime( 2026, 1, 1, 0, 0 ).toInstant( TimeZone.UTC )
val year2025: InstantInterval = interval( start2025, end2025 )
val timelineUi: IntInterval = interval( 0, 800 ) // UI element 800 pixels wide
// Find the selected time at a given UI coordinate using linear interpolation.
val mouseX = 400
val uiPercentage: Double = timelineUi.getPercentageFor( mouseX )
val selectedTime: Instant = year2025.getValueAt( uiPercentage ) // July 2nd at noon.
}
}