TimeAgo KMP
A lightweight Kotlin Multiplatform library for formatting durations into human-readable "time ago" strings.

Features
Installation
Kotlin/Android (Maven Central)
Add the dependency to your build.gradle.kts:
commonMain.dependencies {
implementation("io.github.samuolis:timeago-kmp:0.1.11")
}
Swift Package Manager (iOS/macOS)
In Xcode: File → Add Package Dependencies → Enter:
https:
Or add to your Package.swift:
dependencies: [
.package(url: "https://github.com/samuolis/timeago-kmp", from: "0.1.11")
]
npm (JavaScript/TypeScript)
npm install timeago-kmp
Or with yarn:
yarn add timeago-kmp
Usage
Kotlin
import io.github.samuolis.timeago.timeAgo
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.days
5.minutes.timeAgo()
1.hours.timeAgo()
2.days.timeAgo()
45.seconds.timeAgo()
(-).days.timeAgo()
(-).hours.timeAgo()
Swift
import TimeAgoKMP
TimeAgo.shared.fromSeconds(seconds: 30)
.shared.fromMinutes(minutes: )
.shared.fromHours(hours: )
.shared.fromDays(days: )
.shared.fromDays(days: )
.timeAgoFromSeconds(seconds: )
JavaScript/TypeScript
{ } ;
.();
.();
.();
.();
.(-);
const { TimeAgo } = require('timeago-kmp');
TimeAgo.fromSeconds(300);
Swift Date Extension
import Foundation
import TimeAgoKMP
extension Date {
func timeAgo() -> String {
let seconds (().timeIntervalSince())
.shared.fromSeconds(seconds: seconds)
}
}
postDate ().addingTimeInterval()
(postDate.timeAgo())
Custom Locale
Kotlin:
Output Examples
Supported Platforms
- Android
- iOS (arm64, x64, simulatorArm64)
- macOS (arm64, x64)
- JVM
- JavaScript (browser, Node.js)
- WasmJS (browser, Node.js)
- Linux (x64, arm64)
- Windows (mingwX64)
License
MIT License - see LICENSE for details.