/**
 * 
 * @param {string} str source string 
 * @param {number} lng target length
 * @param {number} arrow add padding to start/end -1 > start , 1 > end
 * @param {string} txt padding string
 * @return {string}
 */
export const padding = (str, lng = 0, arrow = -1, txt = '0') => {
	if(typeof str != 'string') str = str.toString();
	if(typeof txt != 'string') txt = txt.toString();
	if(!isFinite(lng) || lng <= 0) return str;
	if(str.length < lng) return padding(arrow < 0 ? `${txt}${str}` : `${str}${txt}`, lng, arrow, txt);
	return str;
}

/**
 * 
 * @param {*} timestamp timestamp string or number 
 * @param {bool} showSec show second flag
 * @return {string}
 */
export const convertTime = (timestamp, showSec = false) => {
	timestamp = padding(timestamp, 13, 1, '0');
	let d = new Date(parseInt(timestamp));
	return `${d.getFullYear()}-${padding(d.getMonth() + 1, 2)}-${padding(d.getDate(), 2)} ${padding(d.getHours(), 2)}:${padding(d.getMinutes(), 2)}${showSec ? `:${padding(d.getSeconds(), 2)}` : ''}`
}