{"version":3,"sources":["../../../../src/components/Calendar/utils/dateMath.ts"],"sourcesContent":["import { DAYS_IN_WEEK, DEFAULT_WORK_WEEK_DAYS } from './constants';\nimport { getDayIndex, getMonthIndex } from './dateUtils';\nimport type { DateRangeType, DayOfWeek, FirstWeekOfYear } from './constants';\n\n/**\n * Creates a new Date object with the specified year, month, and day, with the time set to midnight.\n */\nexport function createDate(year: number, month: number, day: number): Date {\n  const date = new Date(0);\n  date.setHours(0, 0, 0, 0);\n  date.setFullYear(year, month, day);\n  return date;\n}\n\ntype CivilDate = { year: number; month: number; day: number };\n\n/** Advances calendar fields independently of local timezone gaps. */\nexport function addCivilDays({ year, month, day }: CivilDate, days: number): CivilDate {\n  const date = new Date(0);\n  date.setUTCFullYear(year, month, day + days);\n  return { year: date.getUTCFullYear(), month: date.getUTCMonth(), day: date.getUTCDate() };\n}\n\n/** Checks whether a local date preserved the requested calendar fields without normalization. */\nexport function matchesCivilDate(date: Date, { year, month, day }: CivilDate): boolean {\n  return date.getFullYear() === year && date.getMonth() === month && date.getDate() === day;\n}\n\n/**\n * Returns a date offset from the given date by the specified number of days.\n * @param date - The origin date\n * @param days - The number of days to offset. 'days' can be negative.\n * @returns A new Date object offset from the origin date by the given number of days\n */\nexport function addDays(date: Date, days: number): Date {\n  const result = new Date(date.getTime());\n  result.setDate(result.getDate() + days);\n  return result;\n}\n\n/**\n * Returns a date offset from the given date by the specified number of months.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param months - The number of months to offset. 'months' can be negative.\n * @returns A new Date object offset from the origin date by the given number of months\n */\nexport function addMonths(date: Date, months: number): Date {\n  let result = new Date(date.getTime());\n  const targetMonth = result.getMonth() + months;\n  result.setMonth(targetMonth);\n\n  const normalizedTargetMonth = ((targetMonth % 12) + 12) % 12;\n  if (result.getMonth() !== normalizedTargetMonth) {\n    result = addDays(result, -result.getDate());\n  }\n\n  return result;\n}\n\n/**\n * Returns a date offset from the given date by the specified number of years.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param years - The number of years to offset. 'years' can be negative.\n * @returns A new Date object offset from the origin date by the given number of years\n */\nexport function addYears(date: Date, years: number): Date {\n  let result = new Date(date.getTime());\n  result.setFullYear(date.getFullYear() + years);\n\n  if (result.getMonth() !== date.getMonth()) {\n    result = addDays(result, -result.getDate());\n  }\n\n  return result;\n}\n\n/**\n * Returns a date that is the first day of the month of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the first day of the month.\n */\nexport function getMonthStart(date: Date): Date {\n  return createDate(date.getFullYear(), date.getMonth(), 1);\n}\n\n/**\n * Returns a date that is the last day of the month of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the last day of the month.\n */\nexport function getMonthEnd(date: Date): Date {\n  return addDays(createDate(date.getFullYear(), date.getMonth() + 1, 1), -1);\n}\n\n/**\n * Returns a date that is the first day of the year of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the first day of the year.\n */\nexport function getYearStart(date: Date): Date {\n  return createDate(date.getFullYear(), 0, 1);\n}\n\n/**\n * Returns a date that is the last day of the year of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the last day of the year.\n */\nexport function getYearEnd(date: Date): Date {\n  return addDays(createDate(date.getFullYear() + 1, 0, 1), -1);\n}\n\n/**\n * Returns a date that is a copy of the given date, aside from the month changing to the given month.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param month - The 0-based index of the month to set on the date.\n * @returns A new Date object with the given month set.\n */\nexport function setMonth(date: Date, month: number): Date {\n  return addMonths(date, month - date.getMonth());\n}\n\n/**\n * Compares two dates, and returns true if the two dates (not accounting for time-of-day) are equal.\n * @returns True if the two dates represent the same date (regardless of time-of-day), false otherwise.\n */\nexport function areDatesEqual(date1: Date, date2: Date): boolean {\n  if (!date1 && !date2) {\n    return true;\n  } else if (!date1 || !date2) {\n    return false;\n  } else {\n    return compareDatePart(date1, date2) === 0;\n  }\n}\n\n/**\n * Compare the date parts of two dates\n * @param date1 - The first date to compare\n * @param date2 - The second date to compare\n * @returns A negative value if date1 is earlier than date2, 0 if the dates are equal, or a positive value\n * if date1 is later than date2.\n */\nexport function compareDatePart(date1: Date, date2: Date): number {\n  return (\n    date1.getFullYear() - date2.getFullYear() ||\n    date1.getMonth() - date2.getMonth() ||\n    date1.getDate() - date2.getDate()\n  );\n}\n\n/**\n * Gets the date range array including the specified date. The date range array is calculated as the list\n * of dates accounting for the specified first day of the week and date range type.\n * @param date - The input date\n * @param dateRangeType - The desired date range type, i.e., day, week, month, etc.\n * @param firstDayOfWeek - The first day of the week.\n * @param workWeekDays - The allowed days in work week. Defaults to Monday through Friday.\n * @param daysToSelectInDayView - The number of days to include when using dateRangeType === 'day'\n * for multiday view. Defaults to 1\n * @returns An array of dates representing the date range containing the specified date.\n */\nexport function getDateRange(\n  date: Date,\n  dateRangeType: DateRangeType,\n  firstDayOfWeek: DayOfWeek,\n  workWeekDays?: DayOfWeek[],\n  daysToSelectInDayView: number = 1,\n): Date[] {\n  if (!Number.isFinite(date.valueOf())) {\n    throw new RangeError('date must be valid');\n  }\n\n  if (!Number.isFinite(daysToSelectInDayView) || !Number.isInteger(daysToSelectInDayView)) {\n    throw new RangeError('daysToSelectInDayView must be a finite integer');\n  }\n\n  if (dateRangeType === 'day' && daysToSelectInDayView === 0) {\n    return [];\n  }\n\n  const datesArray: Date[] = [];\n  let startDate: Date;\n  let endDate = null;\n  let maximumRangeLength: number;\n\n  if (!workWeekDays) {\n    workWeekDays = [...DEFAULT_WORK_WEEK_DAYS];\n  }\n\n  const workWeekDayIndices = workWeekDays.map(getDayIndex);\n\n  switch (dateRangeType) {\n    case 'day':\n      // Create a date range for the specified date\n\n      [startDate, endDate] = [date, addDays(date, daysToSelectInDayView)];\n      maximumRangeLength = Math.abs(daysToSelectInDayView);\n\n      // If the start date is after the end date, swap them\n      if (compareDatePart(startDate, endDate) > 0) {\n        /*\n         * For reverse dates we need to add one day to both dates\n         * to ensure correct start date\n         */\n        [startDate, endDate] = [addDays(endDate, 1), addDays(startDate, 1)];\n      }\n\n      break;\n\n    case 'week':\n    case 'workWeek':\n      startDate = getStartDateOfWeek(date, firstDayOfWeek);\n      endDate = addDays(startDate, DAYS_IN_WEEK);\n      if (compareDatePart(date, endDate) >= 0) {\n        startDate = addDays(startDate, DAYS_IN_WEEK);\n        endDate = addDays(endDate, DAYS_IN_WEEK);\n      }\n      maximumRangeLength = DAYS_IN_WEEK;\n      break;\n\n    case 'month':\n      startDate = createDate(date.getFullYear(), date.getMonth(), 1);\n      endDate = addMonths(startDate, 1);\n      maximumRangeLength = 31;\n      break;\n\n    default:\n      throw new Error('Unexpected object: ' + dateRangeType);\n  }\n\n  if (!Number.isFinite(endDate.getTime())) {\n    throw new RangeError('Date range end is outside the representable date range');\n  }\n\n  // Populate the dates array with a range-specific bound so a faulty adapter cannot hang rendering.\n  let nextDate = startDate;\n  for (let index = 0; index < maximumRangeLength && compareDatePart(nextDate, endDate) !== 0; index++) {\n    if (dateRangeType !== 'workWeek') {\n      // push all days not in work week view\n      datesArray.push(nextDate);\n    } else if (workWeekDayIndices.indexOf(nextDate.getDay()) !== -1) {\n      datesArray.push(nextDate);\n    }\n    nextDate = addDays(nextDate, 1);\n  }\n\n  if (compareDatePart(nextDate, endDate) !== 0) {\n    throw new Error('Date range iteration did not reach the end of the requested range');\n  }\n\n  return datesArray;\n}\n\n/**\n * Checks whether the specified date is in the given date range.\n * @param date - The origin date\n * @param dateRange - An array of dates to do the lookup on\n * @returns True if the date matches one of the dates in the specified array, false otherwise.\n */\nexport function isDateInRange(date: Date, dateRange: Date[]): boolean {\n  for (const dateInRange of dateRange) {\n    if (compareDatePart(date, dateInRange) === 0) {\n      return true;\n    }\n  }\n  return false;\n}\n\n/**\n * Returns the week number for a date.\n *\n * @param date - A date to find the week number for.\n * @param firstDayOfWeek - The named day that starts each week.\n * @param firstWeekOfYear - The convention that determines which week is the first week of the year.\n * @returns The week's number in the year.\n */\nexport function getWeekNumber(date: Date, firstDayOfWeek: DayOfWeek, firstWeekOfYear: FirstWeekOfYear): number {\n  // First four-day week of the year - minimum days count\n  const fourDayWeek = 4;\n\n  switch (firstWeekOfYear) {\n    case 'firstFullWeek':\n      return getWeekOfYearFullDays(date, firstDayOfWeek, DAYS_IN_WEEK);\n\n    case 'firstFourDayWeek':\n      return getWeekOfYearFullDays(date, firstDayOfWeek, fourDayWeek);\n\n    default:\n      return getFirstDayWeekOfYear(date, firstDayOfWeek);\n  }\n}\n\n/**\n * Gets the date for the first day of the week based on the given date assuming\n * the specified first day of the week.\n * @param date - The date to find the beginning of the week date for.\n * @returns A new date object representing the first day of the week containing the input date.\n */\nexport function getStartDateOfWeek(date: Date, firstDayOfWeek: DayOfWeek): Date {\n  const year = date.getFullYear();\n  const month = date.getMonth();\n  const day = date.getDate();\n  const firstDayOfWeekIndex = getDayIndex(firstDayOfWeek);\n\n  for (let daysBack = 0; daysBack < 2 * DAYS_IN_WEEK; daysBack++) {\n    const candidate = createDate(year, month, day - daysBack);\n    if (!Number.isFinite(candidate.getTime())) {\n      throw new RangeError('Cannot align an invalid or out-of-range date.');\n    }\n    if (candidate.getDay() === firstDayOfWeekIndex) {\n      return candidate;\n    }\n  }\n\n  throw new RangeError('Could not find a representable week start within two weeks.');\n}\n\n/**\n * Helper function for `getWeekNumber`.\n * Returns week number for a date.\n * @param date - current selected date.\n * @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)\n * @param numberOfFullDays - week settings.\n * @returns The week's number in the year.\n */\nfunction getWeekOfYearFullDays(date: Date, firstDayOfWeek: DayOfWeek, numberOfFullDays: number): number {\n  const firstDayOfWeekIndex = getDayIndex(firstDayOfWeek);\n  const dayOfYear = getDayOfYear(date) - 1;\n  let num = date.getDay() - (dayOfYear % DAYS_IN_WEEK);\n\n  const lastDayOfPrevYear = createDate(date.getFullYear() - 1, getMonthIndex('december'), 31);\n  const daysInYear = getDayOfYear(lastDayOfPrevYear) - 1;\n\n  let num2 = (firstDayOfWeekIndex - num + 2 * DAYS_IN_WEEK) % DAYS_IN_WEEK;\n  if (num2 !== 0 && num2 >= numberOfFullDays) {\n    num2 -= DAYS_IN_WEEK;\n  }\n\n  let num3 = dayOfYear - num2;\n  if (num3 < 0) {\n    num -= daysInYear % DAYS_IN_WEEK;\n    num2 = (firstDayOfWeekIndex - num + 2 * DAYS_IN_WEEK) % DAYS_IN_WEEK;\n    if (num2 !== 0 && num2 + 1 >= numberOfFullDays) {\n      num2 -= DAYS_IN_WEEK;\n    }\n\n    num3 = daysInYear - num2;\n  }\n\n  const nextYearFirstWeekStart = getStartDateOfWeek(createDate(date.getFullYear() + 1, 0, 1), firstDayOfWeek);\n  const nextYearFirstWeekDays = Array.from({ length: DAYS_IN_WEEK }, (_, index) =>\n    addDays(nextYearFirstWeekStart, index),\n  ).filter(nextYearDate => nextYearDate.getFullYear() === date.getFullYear() + 1).length;\n  if (nextYearFirstWeekDays >= numberOfFullDays && compareDatePart(date, nextYearFirstWeekStart) >= 0) {\n    return 1;\n  }\n\n  return Math.floor(num3 / DAYS_IN_WEEK + 1);\n}\n\n/**\n * Helper function for `getWeekNumber`.\n * Returns week number for a date.\n * @param date - current selected date.\n * @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)\n * @returns The week's number in the year.\n */\nfunction getFirstDayWeekOfYear(date: Date, firstDayOfWeek: DayOfWeek): number {\n  const num = getDayOfYear(date) - 1;\n  const num2 = date.getDay() - (num % DAYS_IN_WEEK);\n  const num3 = (num2 - getDayIndex(firstDayOfWeek) + 2 * DAYS_IN_WEEK) % DAYS_IN_WEEK;\n\n  return Math.floor((num + num3) / DAYS_IN_WEEK + 1);\n}\n\n/**\n * Returns the day number for a date in a year:\n * the number of days since January 1st in the particular year.\n * @param date - A date to find the day number for.\n * @returns The day's number in the year.\n */\nfunction getDayOfYear(date: Date): number {\n  const month = date.getMonth();\n  const year = date.getFullYear();\n  let daysUntilDate = 0;\n\n  for (let i = 0; i < month; i++) {\n    daysUntilDate += daysInMonth(i + 1, year);\n  }\n\n  daysUntilDate += date.getDate();\n\n  return daysUntilDate;\n}\n\n/**\n * Returns the number of days in the month\n * @param month - The month number to target (months 1-12).\n * @param year - The year to target.\n * @returns The number of days in the month.\n */\nfunction daysInMonth(month: number, year: number): number {\n  return createDate(year, month, 0).getDate();\n}\n"],"names":["addCivilDays","addDays","addMonths","addYears","areDatesEqual","compareDatePart","createDate","getDateRange","getMonthEnd","getMonthStart","getStartDateOfWeek","getWeekNumber","getYearEnd","getYearStart","isDateInRange","matchesCivilDate","setMonth","year","month","day","date","Date","setHours","setFullYear","days","setUTCFullYear","getUTCFullYear","getUTCMonth","getUTCDate","getFullYear","getMonth","getDate","result","getTime","setDate","months","targetMonth","normalizedTargetMonth","years","date1","date2","dateRangeType","firstDayOfWeek","workWeekDays","daysToSelectInDayView","Number","isFinite","valueOf","RangeError","isInteger","datesArray","startDate","endDate","maximumRangeLength","DEFAULT_WORK_WEEK_DAYS","workWeekDayIndices","map","getDayIndex","Math","abs","DAYS_IN_WEEK","Error","nextDate","index","push","indexOf","getDay","dateRange","dateInRange","firstWeekOfYear","fourDayWeek","getWeekOfYearFullDays","getFirstDayWeekOfYear","firstDayOfWeekIndex","daysBack","candidate","numberOfFullDays","dayOfYear","getDayOfYear","num","lastDayOfPrevYear","getMonthIndex","daysInYear","num2","num3","nextYearFirstWeekStart","nextYearFirstWeekDays","Array","from","length","_","filter","nextYearDate","floor","daysUntilDate","i","daysInMonth"],"mappings":";;;;;;;;;;;QAiBgBA;eAAAA;;QAiBAC;eAAAA;;QAcAC;eAAAA;;QAqBAC;eAAAA;;QA+DAC;eAAAA;;QAiBAC;eAAAA;;QA9IAC;eAAAA;;QAiKAC;eAAAA;;QA1EAC;eAAAA;;QATAC;eAAAA;;QA4NAC;eAAAA;;QAtBAC;eAAAA;;Q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