import React from "react";

type DateTimeProps = {
	d: string;
};

const DateTime: React.FC<DateTimeProps> = ({ d }) => {
	const datetime = Date.parse(d);
	const now = Date.now();
	const diff = (now - datetime) / 1000;
	if (diff < 30) return <span>moments ago</span>;
	if (diff < 60) return <span>{diff}s</span>;
	if (diff < 60 * 60) return <span>{Math.round(diff / 60)}m</span>;
	if (diff < 60 * 60 * 48) return <span>{Math.round(diff / (60 * 60))}h</span>;
	if (diff < 60 * 60 * 24 * 365)
		return <span>{Math.round(diff / (60 * 60 * 24))}d</span>;
	return <span>{Math.round(diff / (60 * 60 * 24 * 365))}y</span>;
};
export default DateTime;
