package com.gh.common.util;

public class SpeedUtils {

	public static String getSpeed(long kSpeed) {
		if (kSpeed >= 1000) {
			float mSpeed = kSpeed / 1024f;
			String str = String.valueOf(mSpeed);
			if (str.length() > 4) {
				str = str.substring(0, 4);
			}
			return str + "MB/s";
		}
		return kSpeed + "K/s";
	}

	public static String getRemainTime(long totalSize, long currentSize, long speed) {
		long remainSize = totalSize - currentSize;
		long remainTime;
		if (speed != 0) {
			remainTime = remainSize / speed;
		} else {
			return "0分0秒";
		}
		int hour = (int) (remainTime / 3600);
		remainTime = (remainTime - hour * 3660);
		int minute = (int) (remainTime / 60);
		int second = (int) (remainTime - minute * 60);
		if (hour != 0) {
			return hour + "时" + minute + "分" + second + "秒";
		} else if (minute != 0) {
			return minute + "分" + second + "秒";
		} else {
			return second + "秒";
		}
	}

}
