The base date as a Date object or timestamp (number)
A new Date object truncated to the start of the year, or Invalid Date if input is invalid
// Basic truncation
const result = truncYear(new Date(2024, 5, 15, 14, 30, 45, 123));
// Returns: January 1, 2024 00:00:00.000
// Already at start of year
const result2 = truncYear(new Date(2024, 0, 1, 0, 0, 0, 0));
// Returns: January 1, 2024 00:00:00.000 (unchanged)
// Works with timestamps
const timestamp = Date.now();
const result3 = truncYear(timestamp);
// Returns: Date at January 1st of current year at 00:00:00.000
// End of year
const result4 = truncYear(new Date(2024, 11, 31, 23, 59, 59, 999));
// Returns: January 1, 2024 00:00:00.000
// Invalid inputs return Invalid Date
const result5 = truncYear(new Date("invalid"));
// Returns: Invalid Date
Truncate a date to the start of the year.
This function sets the date to January 1st at 00:00:00.000 of the same year, effectively removing all time components and resetting the month and day to January 1st.