type nullableDate = Date | string | null;

export const convertToDate = (checkDate: nullableDate): string | null => {
	if (checkDate === null) return null;
	const dateStr = typeof checkDate === "string" ? checkDate : checkDate.toISOString();
	return dateStr === "" ? null : `'${dateStr.substr(0, 10)}'`;
};

export function mysqlDateFormat(inDate: string | Date | null): string {
	let ret: string = "";

	if (typeof inDate !== "undefined" && typeof inDate !== "object" && inDate !== null && inDate !== "") {
		ret = inDate.substr(5, 2) + "-" + inDate.substr(8, 2) + "-" + inDate.substr(0, 4);
	} else if (inDate !== null && typeof inDate === "object") {
		ret =
			inDate.getFullYear() +
			"-" +
			(inDate.getMonth() + 1).toString().padStart(2, "0") +
			"-" +
			inDate.getDate().toString().padStart(2, "0");
	}

	return ret;
}
