package com.base.datarecovery.help

import android.view.View
import org.json.JSONObject
import java.text.SimpleDateFormat
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.getDefault()).format(this)
    }
}