diff --git a/invert-report/src/jsMain/kotlin/com/squareup/invert/common/utils/FormattingUtils.kt b/invert-report/src/jsMain/kotlin/com/squareup/invert/common/utils/FormattingUtils.kt index 7bda3f3..a162935 100644 --- a/invert-report/src/jsMain/kotlin/com/squareup/invert/common/utils/FormattingUtils.kt +++ b/invert-report/src/jsMain/kotlin/com/squareup/invert/common/utils/FormattingUtils.kt @@ -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(",") @@ -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" + } } \ No newline at end of file