package com.pixelized.biblib.utils.extention

import java.text.Format
import java.text.SimpleDateFormat
import java.util.*

fun Date.year(
    default: String? = null,
    formatter: Format = SimpleDateFormat("yyyy", Locale.getDefault()),
): String? = format(
    default = default,
    formatter = formatter
)

fun Date.shortDate(
    default: String? = null,
    formatter: Format = SimpleDateFormat("MMM yyyy", Locale.getDefault()),
): String? = format(
    default = default,
    formatter = formatter
)

private fun Date.format(
    default: String?,
    formatter: Format,
): String? {
    return if (time < 0) {
        default
    } else {
        formatter.format(this).capitalize()
    }
}