/**
 * D3 Time Polyfill - Lightweight time interval functions.
 *
 * This is a drop-in replacement for d3-time, implementing only the time interval
 * floor functions used in the Vega chart time axis label formatter:
 * timeSecond, timeMinute, timeHour, timeDay, timeWeek, timeMonth, timeYear.
 *
 * Each function floors a Date to the nearest interval boundary, which is used
 * to determine the appropriate label granularity for time-series chart axes.
 *
 * @see VD-5022 - [Zero Dependencies] remove d3 dependency
 */
/**
 * Floors a date to the nearest second boundary.
 * Used to detect sub-second (millisecond) granularity.
 *
 * @param {Date} date - Input date.
 * @returns {Date} A new Date floored to the nearest second.
 */
export function timeSecond(date) {
  const d = new Date(date);
  d.setMilliseconds(0);
  return d;
}
/**
 * Floors a date to the nearest minute boundary.
 * Used to detect sub-minute (second) granularity.
 *
 * @param {Date} date - Input date.
 * @returns {Date} A new Date floored to the nearest minute.
 */
export function timeMinute(date) {
  const d = new Date(date);
  d.setSeconds(0, 0);
  return d;
}
/**
 * Floors a date to the nearest hour boundary.
 * Used to detect sub-hour (minute) granularity.
 *
 * @param {Date} date - Input date.
 * @returns {Date} A new Date floored to the nearest hour.
 */
export function timeHour(date) {
  const d = new Date(date);
  d.setMinutes(0, 0, 0);
  return d;
}
/**
 * Floors a date to the start of the day (midnight).
 * Used to detect sub-day (hour) granularity.
 *
 * @param {Date} date - Input date.
 * @returns {Date} A new Date floored to midnight.
 */
export function timeDay(date) {
  const d = new Date(date);
  d.setHours(0, 0, 0, 0);
  return d;
}
/**
 * Floors a date to the start of the week (Sunday).
 * Used to distinguish day vs week label granularity.
 *
 * @param {Date} date - Input date.
 * @returns {Date} A new Date floored to the start of the week (Sunday at midnight).
 */
export function timeWeek(date) {
  const d = new Date(date);
  d.setHours(0, 0, 0, 0);
  d.setDate(d.getDate() - d.getDay());
  return d;
}
/**
 * Floors a date to the first of the month.
 * Used to detect sub-month granularity.
 *
 * @param {Date} date - Input date.
 * @returns {Date} A new Date floored to the 1st of the month at midnight.
 */
export function timeMonth(date) {
  const d = new Date(date);
  d.setDate(1);
  d.setHours(0, 0, 0, 0);
  return d;
}
/**
 * Floors a date to January 1st of the year.
 * Used to detect sub-year (month) granularity.
 *
 * @param {Date} date - Input date.
 * @returns {Date} A new Date floored to January 1st at midnight.
 */
export function timeYear(date) {
  const d = new Date(date);
  d.setMonth(0, 1);
  d.setHours(0, 0, 0, 0);
  return d;
}
