Skip to content

Commit 8098172

Browse files
committed
update ios date time text
1 parent c9e2cc4 commit 8098172

File tree

2 files changed

+8
-36
lines changed

2 files changed

+8
-36
lines changed

iosApp/flare/UI/Component/DateTimeText.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ struct DateTimeText: View {
88
var body: some View {
99
if fullTime {
1010
Text(data.platformValue, style: .date) + Text(data.platformValue, style: .time)
11+
} else if data.shouldShowFull {
12+
Text(data.platformValue, style: .date)
1113
} else {
1214
Text(data.platformValue, style: .relative)
1315
}

shared/src/commonMain/kotlin/dev/dimension/flare/ui/render/UiDateTime.kt

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dev.dimension.flare.ui.render
22

33
import dev.dimension.flare.ui.humanizer.Formatter.full
44
import dev.dimension.flare.ui.humanizer.Formatter.relative
5+
import kotlin.time.Clock
56
import kotlin.time.Instant
67

78
public expect class PlatformDateTime
@@ -17,42 +18,11 @@ public data class UiDateTime internal constructor(
1718
val relative: String = value.relative()
1819
val full: String = value.full()
1920

20-
// val diff: DiffType by lazy {
21-
//
22-
// val compareTo = Clock.System.now()
23-
// val timeZone = TimeZone.currentSystemDefault()
24-
// val time = this.value.toLocalDateTime(timeZone)
25-
// val diff = compareTo - this.value
26-
// when {
27-
// compareTo.toLocalDateTime(timeZone).year != time.year -> {
28-
// DiffType.YEAR_MONTH_DAY
29-
// }
30-
// diff.inWholeDays >= 7 -> {
31-
// DiffType.MONTH_DAY
32-
// }
33-
// diff.inWholeDays >= 1 -> {
34-
// DiffType.DAYS
35-
// }
36-
// diff.inWholeHours >= 1 -> {
37-
// DiffType.HOURS
38-
// }
39-
// diff.inWholeMinutes < 1 -> {
40-
// DiffType.SECONDS
41-
// }
42-
// else -> {
43-
// DiffType.MINUTES
44-
// }
45-
// }
46-
// }
47-
//
48-
// public enum class DiffType {
49-
// DAYS,
50-
// HOURS,
51-
// MINUTES,
52-
// SECONDS,
53-
// YEAR_MONTH_DAY,
54-
// MONTH_DAY,
55-
// }
21+
val shouldShowFull: Boolean by lazy {
22+
val compareTo = Clock.System.now()
23+
val diff = compareTo - this.value
24+
diff.inWholeDays >= 7
25+
}
5626
}
5727

5828
public fun Instant.toUi(): UiDateTime = UiDateTime(this)

0 commit comments

Comments
 (0)