Skip to content

Commit

Permalink
Utility to format the date
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam committed Dec 2, 2024
1 parent 016876c commit 3f826f5
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import com.squareup.invert.models.js.MetadataJsReportModel
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlin.js.Date

object FormattingUtils {
fun Int.formatDecimalSeparator(): String {
if (this < 1000) {
return this.toString()
return if (this < 1000) {
this.toString()
} else {
return toString()
toString()
.reversed()
.chunked(3)
.joinToString(",")
Expand All @@ -33,4 +34,16 @@ object FormattingUtils {

return formattedDate
}

/**
* Formats an epoch time in seconds to a date string in the format "YYYY-MM-DD".
*/
fun formatEpochToDate(epochSeconds: Long): String {
val date = Date(epochSeconds * 1000)
val year = date.getFullYear()
val month = (date.getMonth() + 1).toString().padStart(2, '0') // Months are 0-indexed
val day = date.getDate().toString().padStart(2, '0')

return "$year-$month-$day"
}
}

0 comments on commit 3f826f5

Please sign in to comment.