All files getAdventStartDate.ts

100% Statements 8/8
100% Branches 1/1
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 182x             2x 11x 11x   11x 3x     8x    
import { startOfWeek, differenceInDays, addWeeks } from "date-fns";
 
/**
 *
 * @param {number} churchYear - The full year of the Church year as it will be at Easter
 *                              Sunday (e.g. 2024 means that Advent begins in 2023)
 */
export const getAdventStartDate = (churchYear: number) => {
  const stAndrewsDay = new Date(churchYear - 1, 10, 30);
  const nearestSunday = startOfWeek(stAndrewsDay);
 
  if (differenceInDays(stAndrewsDay, nearestSunday) < 4) {
    return nearestSunday;
  }
 
  return addWeeks(nearestSunday, 1);
};