Add UnitFormat ios implementation
This commit is contained in:
24
shared/src/iosMain/kotlin/app/klottr/util/UnitFormat.ios.kt
Normal file
24
shared/src/iosMain/kotlin/app/klottr/util/UnitFormat.ios.kt
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package app.klottr.util
|
||||||
|
|
||||||
|
import platform.Foundation.NSDate
|
||||||
|
import platform.Foundation.NSDateFormatter
|
||||||
|
import platform.Foundation.NSDateFormatterMediumStyle
|
||||||
|
import platform.Foundation.NSDateFormatterShortStyle
|
||||||
|
import platform.Foundation.NSTimeZone
|
||||||
|
import platform.Foundation.localTimeZone
|
||||||
|
import platform.Foundation.dateWithTimeIntervalSince1970
|
||||||
|
|
||||||
|
actual fun formatRelativeOrTime(ms: Long): String {
|
||||||
|
val date = NSDate.dateWithTimeIntervalSince1970(ms.toDouble() / 1000.0)
|
||||||
|
|
||||||
|
// Fully localized output like:
|
||||||
|
// - "Today, 14:32" / "Yesterday, 2:32 PM" (language + punctuation vary by locale)
|
||||||
|
// - "Sep 20, 2025 at 14:32" or locale-equivalent for older dates
|
||||||
|
return NSDateFormatter().apply {
|
||||||
|
dateStyle = NSDateFormatterMediumStyle
|
||||||
|
timeStyle = NSDateFormatterShortStyle
|
||||||
|
doesRelativeDateFormatting = true // enables "Today"/"Yesterday" in the user’s language
|
||||||
|
timeZone = NSTimeZone.localTimeZone // device zone
|
||||||
|
// locale defaults to user's current; no override here on purpose.
|
||||||
|
}.stringFromDate(date)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user