package com.hmg.hmgDr.util

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

object DateUtils {

    var simpleDateFormat: SimpleDateFormat = SimpleDateFormat("hh:mm:ss", Locale.ENGLISH)

    fun differentDateTimeBetweenDateAndNow(firstDate: Date): String {
        val now: Date = Calendar.getInstance().time
        //1 minute = 60 seconds
        //1 hour = 60 x 60 = 3600
        //1 day = 3600 x 24 = 86400

        var different: Long = now.time - firstDate.time

        val secondsInMilli: Long = 1000
        val minutesInMilli = secondsInMilli * 60
        val hoursInMilli = minutesInMilli * 60
        val daysInMilli = hoursInMilli * 24

        val elapsedDays = different / daysInMilli
        different %= daysInMilli

        val elapsedHours = different / hoursInMilli
        different %= hoursInMilli

        val elapsedMinutes = different / minutesInMilli
        different %= minutesInMilli

        val elapsedSeconds = different / secondsInMilli

        val format = "%1$02d:%2$02d" // two digits
        return String.format(format, elapsedMinutes, elapsedSeconds)
    }

}