/**
 * Calculates the difference in years between two dates.
 * @param date1 - The first date.
 * @param date2 - The second date.
 */
function dateDiffInYears(date1: number, date2: number): number {
	date1 = Number(date1);
	date2 = Number(date2);
	if (date1 <= 0 || date2 <= 0) {
		return 0;
	}
	// Calculate the absolute difference in years
	const millisecondsInYear = 31536e6; // 365.25 days * 24 hours * 60 minutes * 60 seconds * 1000 milliseconds
	const differenceInMilliseconds = Math.abs(date1 - date2);
	// Return the difference in years, truncating to an integer
	return Math.floor(differenceInMilliseconds / millisecondsInYear);
}

// Example usage:
// console.log(dateDiffInYears(date1, date2)); // Output: 23

export default dateDiffInYears;
