-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 Separate the design into expect / actual to possibly support the pl…
…atform the jvm expects (#820)
- Loading branch information
1 parent
d8c28e7
commit 1df1362
Showing
54 changed files
with
497 additions
and
492 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
32 changes: 0 additions & 32 deletions
32
composeApp/src/commonMain/kotlin/com/clipevery/serializer/PreKeyBundleSerializer.kt
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
composeApp/src/commonMain/kotlin/com/clipevery/serializer/RealmInstantSerializer.kt
This file was deleted.
Oops, something went wrong.
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
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
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
73 changes: 8 additions & 65 deletions
73
composeApp/src/commonMain/kotlin/com/clipevery/utils/DateUtils.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 |
---|---|---|
@@ -1,83 +1,26 @@ | ||
package com.clipevery.utils | ||
|
||
import io.realm.kotlin.types.RealmInstant | ||
import java.time.Instant | ||
import java.time.LocalDateTime | ||
import java.time.ZoneId | ||
import java.time.format.DateTimeFormatter | ||
import java.time.temporal.ChronoUnit | ||
import java.util.Calendar | ||
import java.util.Locale | ||
|
||
object DateUtils { | ||
expect fun getDateUtils(): DateUtils | ||
|
||
val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") | ||
interface DateUtils { | ||
|
||
fun getPrevDay(): RealmInstant { | ||
val calendar = Calendar.getInstance() | ||
calendar.add(Calendar.DAY_OF_MONTH, -1) | ||
// Convert milliseconds to seconds for the epochSeconds parameter | ||
val epochSeconds = calendar.timeInMillis / 1000 | ||
// The nanosecondAdjustment parameter is 0 as we're not adjusting nanoseconds here | ||
return RealmInstant.from(epochSeconds, 0) | ||
} | ||
fun getPrevDay(): RealmInstant | ||
|
||
fun getRealmInstant(days: Int): RealmInstant { | ||
val calendar = Calendar.getInstance() | ||
calendar.add(Calendar.DAY_OF_MONTH, days) | ||
// Convert milliseconds to seconds for the epochSeconds parameter | ||
val epochSeconds = calendar.timeInMillis / 1000 | ||
// The nanosecondAdjustment parameter is 0 as we're not adjusting nanoseconds here | ||
return RealmInstant.from(epochSeconds, 0) | ||
} | ||
fun getRealmInstant(days: Int): RealmInstant | ||
|
||
fun getDateText(date: LocalDateTime): String? { | ||
val now = LocalDateTime.now() | ||
fun getDateText(date: LocalDateTime): String? | ||
|
||
if (date.toLocalDate().isEqual(now.toLocalDate())) { | ||
val hour = ChronoUnit.HOURS.between(date, now) | ||
val minutes = ChronoUnit.MINUTES.between(date, now) | ||
val seconds = ChronoUnit.SECONDS.between(date, now) | ||
|
||
if (hour < 1 && minutes < 1 && seconds < 60) { | ||
return "Just_now" | ||
} | ||
return "Today" | ||
} | ||
|
||
val yesterday = now.minusDays(1) | ||
if (date.toLocalDate().isEqual(yesterday.toLocalDate())) { | ||
return "Yesterday" | ||
} | ||
|
||
return null | ||
} | ||
|
||
fun getYYYYMMDD(date: LocalDateTime = LocalDateTime.now()): String { | ||
return dateFormatter.format(date) | ||
} | ||
fun getYYYYMMDD(date: LocalDateTime = LocalDateTime.now()): String | ||
|
||
fun getDateText( | ||
date: LocalDateTime, | ||
pattern: String, | ||
locale: Locale, | ||
): String { | ||
val formatter: DateTimeFormatter = | ||
Memoize.memoize(pattern, locale) { | ||
DateTimeFormatter.ofPattern(pattern, locale) | ||
}() | ||
return formatter.format(date) | ||
} | ||
|
||
fun convertRealmInstantToLocalDateTime(realmInstant: RealmInstant): LocalDateTime { | ||
// 1. 从 RealmInstant 获取秒和纳秒 | ||
val epochSeconds = realmInstant.epochSeconds | ||
val nanosecondsOfSecond = realmInstant.nanosecondsOfSecond | ||
|
||
// 2. 使用 Instant.ofEpochSecond 创建 Instant | ||
val instant = Instant.ofEpochSecond(epochSeconds, nanosecondsOfSecond.toLong()) | ||
): String | ||
|
||
// 3. 使用系统默认的时区将 Instant 转换为 LocalDateTime | ||
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()) | ||
} | ||
fun convertRealmInstantToLocalDateTime(realmInstant: RealmInstant): LocalDateTime | ||
} |
Oops, something went wrong.