package cz.uhk.fim.dragonboatassistant.util;

import java.util.concurrent.TimeUnit;

import android.location.Location;

public class Converter {
	
	TimeUnit convertFrom;
	TimeUnit convertTo;
	private Converter millisToSecsConverter;
	
	public long convertTime(long time) {
		return convertTo.convert(time, convertFrom);
	}
	
	public long convertTime(long time, TimeUnit convertTo, TimeUnit convertFrom) {
		return convertTo.convert(time, convertFrom);
	}
	
	public float convertToKmPerHour(float mPerSec) {
		return (float) (3.6 * mPerSec);
	}
	
	public float getSpeedInMPS(Location from, Location to, long timeFrom, long timeTo) {
		float distance = from.distanceTo(to);
		long time = millisToSecsConverter.convertTime((timeTo - timeFrom), TimeUnit.SECONDS, TimeUnit.MILLISECONDS);
		float speed = distance / time;
		return speed;
	}

	public Converter() {
		super();
	}

	public Converter(TimeUnit convertFrom, TimeUnit convertTo) {
		super();
		this.convertFrom = convertFrom;
		this.convertTo = convertTo;
	}

}
