package com.cygnusa.hyperm.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UtilService {

    public boolean isNetworkAvailable(Context context) {
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) {
                for (NetworkInfo anInfo : info) {
                    if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public static String getTimeInterval(Context context, SimpleDateFormat df, String fromTime, String toTime) {
        String finalTime = null;
        try {
            Date date1 = df.parse(fromTime);
            Date date2 = df.parse(toTime);

            long mills = date2.getTime() - date1.getTime();
            Log.e("Data1", "" + date1.getTime());
            Log.e("Data2", "" + date2.getTime());

            Log.e("mills", String.valueOf(mills));
            double seconds = mills / 1000.0;
            int finalSeconds = (int) seconds;
            finalTime = String.valueOf(finalSeconds);
            Log.e("secs", finalTime);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        return finalTime;
    }
}
