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