/**
 * 数据转换
 */
export default class DataConversion {
	static doConversion(val) {
		var l = val.toString().length;
		var text = ""
		if (l < 4) {
			text = val
		} else if (l >= 4 && l < 5) {
			//text = (val / 1000).toFixed(1).toString() + "k"
			text = (Math.floor((val / 1000)*100)/100).toString() + "k"
		} else if (l >= 5 && l < 7) {
			//text = (val / 10000).toFixed(1).toString() + "w"
			text = (Math.floor((val / 10000)*100)/100).toString() + "w"
		} else if (l >= 7 && l < 9) {
			//text = (val / 1000000).toFixed(1).toString() + "m"
			text = (Math.floor((val / 1000000)*100)/100).toString() + "m"
		} else if (l >= 9 && l < 10) {
			//text = (val / 100000000).toFixed(1).toString() + "E"
			text = (Math.floor((val / 100000000)*100)/100).toString() + "E"
		} else if (l >= 10 && l < 12) {
			//text = (val / 1000000000).toFixed(1).toString() + "b"
			text = (Math.floor((val / 1000000000)*100)/100).toString() + "b"
		} else if (l >= 12 && l < 13) {
			//text = (val / 100000000000).toFixed(1).toString() + "t"
			text = (Math.floor((val / 100000000000)*100)/100).toString() + "t"
		} else if (l >= 13 && l < 17) {
			text = (val / 1000000000000).toFixed(1).toString() + "g"
			//text = (Math.floor((val / 1000000000000)*100)/100).toString() + "g"
		} else if (l >= 17) {
			//text = (val / 10000000000000000).toFixed(1).toString() + "z"
			text = (Math.floor((val / 10000000000000000)*100)/100).toString() + "z"
		}
		//console.log(text)
		return text
	}

	isSameDay(timer1, timer2) {
		if (this.formatTime(timer1, "yyyy-MM-dd") == this.formatTime(timer2, "yyyy-MM-dd")) {
			return true;
		} else {
			return false;
		}
	}

	formatTime(date, fmt) {
		var o = {
			"M+": date.getMonth() + 1, // 月份
			"d+": date.getDate(), // 日
			"h+": date.getHours(), // 小时
			"m+": date.getMinutes(), // 分
			"s+": date.getSeconds(), // 秒
			"q+": Math.floor((date.getMonth() + 3) / 3), // 季度
			"S": date.getMilliseconds() // 毫秒
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	}
}