package com.tgv.malware.utils

import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale


object KotlinExt {

    fun Number.toFormatSize(count: Int = 1): String {
        var suffix = "B"
        var fSize = this.toDouble()
        if (fSize > 1024) {
            suffix = "KB"
            fSize /= 1024.0
        }
        if (fSize > 1024) {
            suffix = "MB"
            fSize /= 1024.0
        }
        if (fSize > 1024) {
            suffix = "GB"
            fSize /= 1024.0
        }
        return String.format("%.${count}f %s", fSize, suffix)
    }

    fun Long.toFormatTime(): String {
        return SimpleDateFormat("MMM dd,yyyy", Locale.ENGLISH).format(this)
    }

    fun Long.toFormatTime2(): String {
        return SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(this)
    }

    fun Long.toFormatTime3(): String {
        return SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).format(this)
    }

    fun Long.toFormatTime4(): String {
        return SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).format(this)
    }

    fun Long.toFormatMinute(): String {
        return SimpleDateFormat("mm", Locale.ENGLISH).format(this)
    }

    fun Long.toFormatHHMinute(): String {
        return SimpleDateFormat("HH:mm", Locale.ENGLISH).format(this)
    }


    fun Array<String>.array2String(): String {
        val stringBuilder = StringBuilder()
        forEach {
            stringBuilder.append(it)
        }
        return stringBuilder.toString()
    }

    fun currentDate(): String {
        val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
        val currentDate = Calendar.getInstance().time
        return dateFormat.format(currentDate)
    }

}