Skip to content

🆕 HumanReadable: data formatting utilities for KMP

You can reply to this article at https://medium.com/@jacobras/humanreadable-data-formatting-utilities-for-kmp-3e51629c95bc.

I made a small Kotlin Multiplatform library that allows formatting relative dates and filesizes. It’s called HumanReadable and it’s available on GitHub: https://github.com/jacobras/Human-Readable.

In the current version, 1.2.0, the following 11 languages are supported: Czech, Dutch, English (default), French, German, Italian, Indonesian, Russian, Spanish, Turkish and Ukrainian. The library works with kotlinx-datetime.

Features

🕰️ Relative time

HumanReadable.timeAgo(now - 134.minutes) // "2 hours ago"
HumanReadable.timeAgo(now + 8.minutes) // "in 8 minutes"

⏱️ Duration

HumanReadable.duration(5.seconds) // "5 seconds"
HumanReadable.duration(7.days) // "1 week"
HumanReadable.duration(544.hours) // "3 weeks"

📂 File size

HumanReadable.fileSize(333) // "333 B"
HumanReadable.fileSize(2_048, decimals = 1) // "2.0 kB"
HumanReadable.fileSize(21_947_282_882, decimals = 2) // "20.44 GB"

GitHub

https://github.com/jacobras/Human-Readable