package es.verdnatura.presentation.view.feature.sacador.mapper

import android.content.Context
import es.verdnatura.R
import es.verdnatura.presentation.common.convertToDateString
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList

fun List<CollectionVO>.toDateFormat(context:Context): ArrayList<CollectionVO> {
    val collections : ArrayList<CollectionVO> = ArrayList()
    this.forEach {
        collections.add(CollectionVO(
            collectionFk = it.collectionFk,
            created = getCalendarFromDate(it.created,context).convertToDateString()
        ))

    }
    return collections
}


private fun getCalendarFromDate(date:String,context:Context): Calendar {
    val sdf = SimpleDateFormat(context.getString(R.string.dateFormat))
    val cal = Calendar.getInstance()
    cal.time = sdf.parse(date)!!
    return cal
}